Tell me, please, how to https://regex101.com write a regular expression for replacing the @ sign with the text instagram.com/» .
|
1 answer
Probably so:
$text = 'Текст от @vanechka.'; $patt = '~@([^\s.,!?-]+)~iu'; $repl = 'instagram.com/$1'; $text = preg_replace($patt, $repl, $text); echo $text; - @ Maxim A. may still need to wrap the text instagram.com/$1 in html tags to get a hyperlink as a result. - Edward
- By the way, you can do without parentheses in a regular expression, if you replace
$1with$0in the substitution line - mymedia - 2@mymedia without brackets you get full compliance with the template, and you must discard the "@". - Edward
|
str_replace. - Wiktor Stribiżew$s = str_replace("@", "instagram/", $s);- Wiktor Stribiżew