Solved

PHP - Is $string1 contained in $string2 ?

Posted on 2012-03-22
3
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

623 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