So what I am trying to do is to match a regular expression which has an opening <p>;
tag and a closing </;p>
tag.This is the code I wrote:
<?php
$input = "<p>just some text</p> more text!";
$input = preg_replace('/<p>[^(<\/p>)]+?<\/;p>/','<p>$1</p>',$tem);
echo $input;
?>
So the code does not seem to replace <p>
with <p>
or replace </p>
with </p>
.I think the problem is in the part where I am checking all characters expect '</p>
. I don't think the code [^(<\/p>)]
is grouping all the characters correctly. I think it checks if any of the characters are not present and not if the entire group of characters is not present. Please help me out here.
$1<\/p>,$tem);` -- you're missing a single-quote here. Are you sure that's not the issue?
– Amal Murali Dec 19 '13 at 18:16