Michael4172 Posted May 8, 2006 Share Posted May 8, 2006 When using something like: [code]if(stristr("$file","¡AP: News¡") )[/code]I would expect it to only hit true on an exact hit, ¡AP: News¡, however it seems to ignore the ¡ at the beginning and end and return true on something like ¡AP: News Text¡Is there any way to ensure that it only returns true on that exact string with the ¡ at the beginning and end? Quote Link to comment Share on other sites More sharing options...
Michael4172 Posted May 9, 2006 Author Share Posted May 9, 2006 After experiementing a bit more looks like it acts in an unintended way. I have: [code]if(stristr("$word_scan","$key_word") ) { $contents = str_replace("¿0a¡<br>¿0a¡¡¡20", "¿0a¡<br>¿0a¡¡¡19", $contents);}[/code]I *THOUGHT* the if statement would go to the first occurence of $key_word, and then soon as it finds it, have the file pointer go to the first occurence of str_replace and replace it.However, it appears as though as long as anything matches the $key_word, it rewrites ever occurance of str_replace within $contents.Any ideas how I can rework it so that it will do how I thought it would do? Quote Link to comment Share on other sites More sharing options...
zq29 Posted May 9, 2006 Share Posted May 9, 2006 Not sure if I have gone about this the long way, but this is the idea that first popped into my head...[code]<?php$needle = "fox";$haystack = "The quick brown fox jumps over the lazy dog - What a great fox he is!";$replace = "elephant";if(strpos($haystack,$needle)) { $pos = strpos($haystack,$needle); $nlen = strlen($needle); $tlen = strlen($haystack); $newhaystack = substr($haystack,0,$pos).$replace.substr($haystack,($pos+$nlen),$tlen); echo $newhaystack;} else { echo "$needle not found in $haystack.";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Michael4172 Posted May 10, 2006 Author Share Posted May 10, 2006 Thanks, that's an interesting way of doing it, I'll play with it and see how it works out :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.