ki Posted October 31, 2007 Share Posted October 31, 2007 hey guys, havent asked something in awhile but now ive got this new question I got help from someone on making data from an array turn into links with this function: function searchLinks($searchStr) { $searchAry = explode(",", $searchStr); foreach ($searchAry as $key => $term) { $searchAry[$key] = "<a href=\"search.php?t=".urlencode(trim($term))."\">" . trim($term) . "</a>"; } $searchStr = implode(", ", $searchAry); return $searchStr; } what I want it to do is also detect breaks such as "\n" so it would also treat breaks as it being seperated and returning back to a break Quote Link to comment https://forums.phpfreaks.com/topic/75571-search-links/ Share on other sites More sharing options...
kratsg Posted October 31, 2007 Share Posted October 31, 2007 I need more information, why are there "\n" breaks? Are you reading this from a file? Are you manually inserting these breaks? If you are getting them because you read from a file, then, for each line you loop through, apply the trim function before doing anything with it. $line = trim($line);//removes line breaks at the ends, and extra white spacing all around If you are manually inserting them, replace \n with commas: Unescaped: str_replace(",","\n",$string); Escaped: str_replace(",","\\n",$string); I think you may need to escape the "\n" but try it both ways. Quote Link to comment https://forums.phpfreaks.com/topic/75571-search-links/#findComment-382349 Share on other sites More sharing options...
ki Posted October 31, 2007 Author Share Posted October 31, 2007 its being grabbed from a multi-line database entry and a break is \n. but i dont want the commas to also be breaks Quote Link to comment https://forums.phpfreaks.com/topic/75571-search-links/#findComment-382353 Share on other sites More sharing options...
kratsg Posted October 31, 2007 Share Posted October 31, 2007 Oh, sorry, switch that around, I'm a bit dsylexic today o_o Unescaped: str_replace("\n",",",$string); Escaped: str_replace("\\n",",",$string); Quote Link to comment https://forums.phpfreaks.com/topic/75571-search-links/#findComment-382360 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.