divinequran Posted August 17, 2009 Share Posted August 17, 2009 Hi, I use a form and get the post value of a textarea field in a variable. How do i Parse the pre tag and so htmlentities to the data present inside the pre tag. please help. Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/ Share on other sites More sharing options...
thebadbad Posted August 17, 2009 Share Posted August 17, 2009 Um, what? Is this what you want?: echo '<pre>' . htmlentities($_POST['fieldname']) . '</pre>'; Else ask a proper question; no offence. Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/#findComment-899906 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Hmm my preg_replace is a skills are a little iffy. <?php echo preg_replace_callback("/<(pre)>(.*?)<\/\\1>/ism", create_function("$matches", "return htmlspecialchars($matches[2]);", $input); ?> I'm not sure if you have to backslash < and > or not in regular expressions. so you might have to come back Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/#findComment-899909 Share on other sites More sharing options...
thebadbad Posted August 17, 2009 Share Posted August 17, 2009 Hmm my preg_replace is a skills are a little iffy. <?php echo preg_replace_callback("/<(pre)>(.*?)<\/\\1>/ism", create_function("$matches", "return htmlspecialchars($matches[2]);", $input); ?> I'm not sure if you have to backslash < and > or not in regular expressions. so you might have to come back Oh, maybe that was what the OP meant You just have to use single quotes instead of double quotes in order for it to work. And your pattern could simply be '~<pre>(.*?)</pre>~is' And then use $matches[1] in the replacement. Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/#findComment-899934 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Kind of getting off topic and all, but what's the difference between ~, /, % and a couple other things like that for surrounding the search? Can't seem to find that stuff on regularexpressions.info Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/#findComment-899940 Share on other sites More sharing options...
thebadbad Posted August 17, 2009 Share Posted August 17, 2009 They're called pattern delimiters, and can be any non-white space, non-alphanumeric ASCII character (except a backslash). And it's always smart to use delimiters that don't appear within the pattern, so you don't have to escape them. Quote Link to comment https://forums.phpfreaks.com/topic/170617-parse-value/#findComment-899959 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.