Solved

PHP - Is $string1 contained in $string2 ?

Posted on 2012-03-22
3
501 Views
Last Modified: 2012-03-22
Hello,

I want to see if this exact string   href='r/  is contained in $mtopics
If not, then run 2 lines of code.

But, it always runs it, even if the string is present.
Can you help?

<?PHP
if(stristr($mtopics, "href='r/") === FALSE) {
$mtopics=str_replace("href='","href='$pre",$mtopics);
$reltopics=str_replace("href='","href='$pre",$reltopics);
}
?>

Thanks, Greg
0
Comment
Question by:gregsschipper
3 Comments
 
LVL 4

Accepted Solution

by:
petr_hlucin earned 500 total points
ID: 37754503
Use the following:
<?PHP
if(stristr($mtopics, 'href=\'r/') === FALSE) {
$mtopics=str_replace("href='","href='$pre",$mtopics);
$reltopics=str_replace("href='","href='$pre",$reltopics);
}
?>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37754630
Please post the test data, thanks.
0
 

Author Closing Comment

by:gregsschipper
ID: 37754838
The BEST! Many Thanks, Greg - www.adventdigital.net
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWK: digits < 10 add a zero how? 11 27
Ajax and PHP 4 31
AJAX Wordpress Not Reading Variable 2 32
PowerShell logging 1 17
If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question