Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.