andyhajime Posted May 29, 2010 Share Posted May 29, 2010 Hi all, What the coding does is suppose to do is run a sql_query on the database, fetch the id of the names in the $TEXT (if exist) and replace it with the <a> tag linking to their profile... but I couldn't quit understand why I keep receiving an "strstr(): Empty delimiter". Please help. $TEXT = "There you see andy walks on the road to that azy house"; $FIND = mysql_query("SELECT * FROM userdata WHERE uename != '0'"); while($FOUND = mysql_fetch_array($FIND)) { $UENAME = $FOUND['uename']; // note: first result is 'andy' (id: 1) followed by 'misa' (id: 2) then 'azy' (id: 3) if(strstr($TEXT, $UENAME)) //<--- ERROR: Warning: strstr() [function.strstr]: Empty delimiter in /home/public_html/ajax.php on line 59 { $TAGNAME = ' <a href="profile.php?id='.$FOUND['id'].'">' . $UENAME . '</a> '; $TEXT = str_replace($UENAME, $TAGNAME, $TEXT); } else { // do nothing } } // result: There you see <a href="profile.php?id=1">andy</a> walks on the road to that <a href="profile.php?id=3">azy</a> house Quote Link to comment https://forums.phpfreaks.com/topic/203282-strstr-empty-delimiter-issue/ Share on other sites More sharing options...
kalivos Posted May 29, 2010 Share Posted May 29, 2010 I'm guessing something is wrong with your query. I would try changing the line with a query to: $FIND = mysql_query("SELECT * FROM userdata WHERE uename != '0'") or die( echo "Mysql Error: ".mysql_error() ); Quote Link to comment https://forums.phpfreaks.com/topic/203282-strstr-empty-delimiter-issue/#findComment-1065119 Share on other sites More sharing options...
ZachMEdwards Posted May 29, 2010 Share Posted May 29, 2010 You can use @strstr to ignore the error. And you also don't need that } else { do nothing part... Just remove it. Quote Link to comment https://forums.phpfreaks.com/topic/203282-strstr-empty-delimiter-issue/#findComment-1065149 Share on other sites More sharing options...
andyhajime Posted May 30, 2010 Author Share Posted May 30, 2010 Guys, I've just find out the problem. Apparently one of the 'uename' in the database is EMPTY/Blank. When I've replace the 0 with nothing, then it works. It's no wonder it say "Empty delimiter" in strstr, the strsrt is getting an 'empty' value. lols $FIND = mysql_query("SELECT * FROM userdata WHERE uename != ''") ZachMEdwards: Thanks man... the 'do nothing' part is normally there for checking only like the sample below. I usually don't use the 'do nothing' method unless I encounter errors it the code. But thanks yeah for responding. Appreciate it. if(strstr($email, "@")) { echo 'found'; //...and do something } else { echo 'not found'; // do nothing } Quote Link to comment https://forums.phpfreaks.com/topic/203282-strstr-empty-delimiter-issue/#findComment-1065271 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.