Jump to content

preg_replace UTF-8


techboy999

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
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
Share on other sites

?476f646d6f7267656e2048e56265722064752068617220736f76657420676f6474206f67206472f86d74204e6f676c652046616e7461736b7469736b65206472f86d6d652c2048617220647520696b6b652065742062696c6c656465206a6567206de52073652073f86465206f67206876616420657220646974206e61766e206f672068766f7220657220647520667261203f

 

some cryptic

Link to comment
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.