php - Dynamically creating preg pattern? -
hello.
i want try , make bbcode parser, , far know, preg functions convenient find , replace bbcode html.
in past have used lot of str_replace on , over, isn't efficient.
i want create bbcode , store in db, given bbcode structure:
[image]{url}[/image] and html: <img src="{url}" alt="" .. />
how can use php compare these 2 inputs , find necessary preg pattern use when parsing bbcode in content?
what want achieve db storing pattern, , when time parse large text bbcodes, know how it. no hardcoding.
i searched bit try , find relevant topics on this, find exact patterns on how resolve url bbcode etc, pardon me if exist somewhere.
store regexp , replacement patterns in db:
regexp: \[image\](.*?)\[/image\] replacement: <img src="$1"/> then later retrieve these database , call preg_replace() them arguments. note should able single call, since can specify regexp , replacement arrays, , perform of them @ once.
Comments
Post a Comment