unidox Posted July 26, 2008 Share Posted July 26, 2008 I was wondering how I would go about doing something like this: {title}lala{/title} Thats what smarty uses, and I was wondering how I can do the same thing using php, a function that gets the info inside a tag. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 You'll have to use regex for that. Check out the regex forum for similar posts. Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/#findComment-600375 Share on other sites More sharing options...
unidox Posted July 26, 2008 Author Share Posted July 26, 2008 I looked at the php function ereg, but I still dont get how I would find the title. Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/#findComment-600380 Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 You'll need to understand regex in order to use any of the ereg_* or preg_* functions. Here are some resources on regex Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/#findComment-600393 Share on other sites More sharing options...
unidox Posted July 26, 2008 Author Share Posted July 26, 2008 I made this function, seems to work. How is it? function get_info($tag, $content) { $content = preg_replace("@\{" . $tag . "\}(.+?)\{\/" . $tag . "\}@", "" . $tag . " = $1", $content); return $content; } Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/#findComment-600419 Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 I'm no regex expert so cant give you any feedback on the efficiency of your regex. However you could modify you regex abit so it finds tags automatically, like: function get_info($content) { $content = preg_replace('@\{([a-z]+)\}(.+)\{\/\1\}@is', "$1 = $2<br />", $content); return $content; } $str = '{title}lala{/title} {body}hello world{/body}'; echo get_info($str); Quote Link to comment https://forums.phpfreaks.com/topic/116749-how/#findComment-600431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.