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 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. 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 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); Link to comment https://forums.phpfreaks.com/topic/75571-search-links/#findComment-382360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.