malisokan
malisokan

Reputation: 5467

How to allow characters and whitspaces in PHP with UTF-8 support?

I want to search/allow characters and whitespaces. This works with ANSI/LATIN-1 characters:

$pattern = '#<a [\W\w]* href="1"#i';

I tried this, but obviously it does not work:

mb_internal_encoding('UTF-8');
mb_regex_encoding("UTF-8");
$pattern = '/<a[\pLN\W]* href="1"/ui';

Upvotes: 0

Views: 74

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89574

use this instead

$pattern = '~<a [\pL\s]*\bhref="1"~ui';



<a  #begin with a tag + a space
[\pL\s]*  # zero or more unicode letters or blank characters (space newline tab)
\bhref="1" # href="1" not preceded by a letter or a number

ui # modifier u for unicode string, i case insensitive

Upvotes: 1

Related Questions