NickV Posted June 8, 2011 Share Posted June 8, 2011 Hi guys, In a CMS I want the user to be able to enter a short tag / snippet such as: [tag_name page=page_name' length='100] Where tag_name is the name of the short tag and page and length are 2 parameters. I need to check whether this tag has been added to the content and extract the values of the 2 parameters. I'm not sure exactly how to do this. I thought preg_match() would be of some use but I'm useless at regular expressons :-\ Thanks for your help Link to comment https://forums.phpfreaks.com/topic/238770-creating-short-tags-code-snippets/ Share on other sites More sharing options...
Ollifi Posted June 8, 2011 Share Posted June 8, 2011 I´m not sure do you mean this but: <?php $content = "Some Content Here"; $from = array("/\[tag_name page=\'(.*?)\' length=\'(.*?)\'\]/is"); $to = array("Tag name $1, length $2"); $content = preg_replace($from, $to, $content); print $content; ?> If you want to execute a function then it would go <?php $content = "Some Content Here"; function someFunction($var1, $var2){ // do something with the var1 & var2 } $from = array("/\[tag_name page=\'(.*?)\' length=\'(.*?)\'\]/e"); $to = array('someFunction("$1", "$2")'); $content = preg_replace($from, $to, $content); print $content; ?> Link to comment https://forums.phpfreaks.com/topic/238770-creating-short-tags-code-snippets/#findComment-1226898 Share on other sites More sharing options...
NickV Posted June 8, 2011 Author Share Posted June 8, 2011 That great, thanks I changed it a bit to: <?php $pattern = "/\[tag_name page=(.*?) length=(.*?)\]/is"; preg_match($pattern, $this->content, $matches); echo $matches[1]." ".$matches[2]; ?> to extract the parameters from the content. I also removed the apostrophes from the parameters so it will search for: [tag_name page=page_name length=100] Cheers Link to comment https://forums.phpfreaks.com/topic/238770-creating-short-tags-code-snippets/#findComment-1226931 Share on other sites More sharing options...
Ollifi Posted June 8, 2011 Share Posted June 8, 2011 Ok, good if it helped =) Just remember to mark this topic solved if you dont need more help? Link to comment https://forums.phpfreaks.com/topic/238770-creating-short-tags-code-snippets/#findComment-1227087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.