问题
If i have the string [link="*"]
where * is a wildcard how could i then use php to replace the string with <a href="*">
where * is the same value as before?
Is preg_replace the best way to do this?
Thanks, any help appreciated!
回答1:
preg_replace('~\[link="(.*?)"\]~', '<a href="$1">', $text);
回答2:
$link = '[link="http://www.google.com/"]';
$link = preg_replace('/\[link="(.*)"\]/', '<a href="$1">', $link);
来源:https://stackoverflow.com/questions/7050152/how-can-i-use-phps-preg-replace-with-a-simple-string-and-wildcards