Jump to content

search links...


ki

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.