I have a lot of shortcodes left in my posts from a non-working plugin of this type:[download#434]
or [download#434#nohits]
or [download#68#size]
How to use regular expressions to overwrite all of them to the same type:[download id="68"] ?
I have a lot of shortcodes left in my posts from a non-working plugin of this type:[download#434]
or [download#434#nohits]
or [download#68#size]
How to use regular expressions to overwrite all of them to the same type:[download id="68"] ?
$result = preg_replace("/\[download#([0-9]+).*?]/ium", "[download id=\"$1\"]", $string); where $ string is the string to be processed.
m modifier were stuffed into the regular season? P, S. In such a regular schedule, neither u nor i are needed, and the more 'm'. - Vismani and u may well slow down the processing of preg_replace (strongly depends on the version of php), m runs idle and does not cause any harm until someone looks at your regulars and does the same, but using ^ , $ . - Visman Nov. $string = '[download#688#nohits] as [download#34]'; $pattern = '/\[(\w+)#(\d+).*?\]/im'; $replacement = '[$1 id="$2"]'; echo preg_replace($pattern, $replacement, $string); Source: https://ru.stackoverflow.com/questions/592390/
All Articles