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? Link to comment https://forums.phpfreaks.com/topic/9335-stristr-oddities/ 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? Link to comment https://forums.phpfreaks.com/topic/9335-stristr-oddities/#findComment-34623 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] Link to comment https://forums.phpfreaks.com/topic/9335-stristr-oddities/#findComment-34727 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 :) Link to comment https://forums.phpfreaks.com/topic/9335-stristr-oddities/#findComment-34953 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.