Solved

PHP - Is $string1 contained in $string2 ?

Posted on 2012-03-22
3
485 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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
Please post the test data, thanks.
0
 

Author Closing Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now