PHP Regex to extract parameters within double square brackets (Modx Tags) -
i'm trying write regex extract value of particular parameter array of content in modx database. format of tags is:
[[!video? &path=`_path_to_video` &width=`123` &height=`123` &someotherparm=`bar`]]
i trying content of &path parameter using regex:
preg_match_all('/\[\[path=`(.*?)`\]\]/', $content, $tags, preg_pattern_order) ;
but without luck - returns empty arrays when dump $tags variable.
something wrong regex?
your pattern doesn't match tag format:
preg_match_all('/&path=`([^`]+)`/', $content, $tags, preg_pattern_order);
- match
&path=
backtick, then - match not backtick until backtick , capture it
if need match existence of [[
, closing ]]
then:
preg_match_all('/\[\[.*&path=`([^`]+)`.*\]\]/', $content, $tags, preg_pattern_order);
Comments
Post a Comment