Jump to content

Recommended Posts

Hello guys

I sitting here and try to get a string in to links, I am almost there just problem I have is that some special characters will not link to the link

I need get the the preg_replace to use UTF-8, I know it's possible with a parameter /u, but I cant find out where to place it

 

Here is the code:

$str = $message4;

// Url Template
$template = '<a href="search.php?q=%1$s">%1$s</a>';

// Replace Words
echo preg_replace("/(?!(?:[^<]+>|[^>]+<\/a>))\b([a-å]+)\b/is", sprintf($template, "\\1"), $str);
Link to comment
https://forums.phpfreaks.com/topic/304034-preg_replace-utf-8/
Share on other sites

Before that,

[a-å]+
will not work: character ranges work on bytes (or Unicode codepoints) and that range will cover far more than just letters.

 

So you're trying to link all words. I'd go for

[\pL']+
to match letters and apostrophes.

 

As for getting Unicode mode, that's the /u flag. "Flags" go after the ending delimiter - you're using two of them already...

Link to comment
https://forums.phpfreaks.com/topic/304034-preg_replace-utf-8/#findComment-1546914
Share on other sites

?476f646d6f7267656e2048e56265722064752068617220736f76657420676f6474206f67206472f86d74204e6f676c652046616e7461736b7469736b65206472f86d6d652c2048617220647520696b6b652065742062696c6c656465206a6567206de52073652073f86465206f67206876616420657220646974206e61766e206f672068766f7220657220647520667261203f

 

some cryptic

Edited by techboy999
Link to comment
https://forums.phpfreaks.com/topic/304034-preg_replace-utf-8/#findComment-1546917
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.