I am trying to replace all the tags in a file like {{name:something}}
to some certain values.
Note that in {{name::something}}
only something might warry. Like {{name:title}}
or {{name:content}}
. That "name" will always be there.
Anyway,
I used preg_match_all and preg_replace, it all worked out. I found the matches with this regular expression: $patmatch="/{{name:[a-zA-Z0-9._-]+}}/";
My problem is the following:
When a tag like this does not match the pattern (it has a syntax error), like {{notname:something}}
or {{name something}}
or {{ }}
i must throw an exception.
How do i know if the tag is there, but with a syntax error?
Can i somehow make another pattern search to check if it's a tag (between {{
and }}
) and if it's not like {{name:something}}
?
Any help would be appreciated, Thanks!