How can i use php's preg_replace with a simple string and wildcards?

巧了我就是萌 提交于 2021-02-07 17:24:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!