Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preg_replace simple task?

Status
Not open for further replies.

webdev007

Programmer
Sep 9, 2005
168
I seem not to grasp the concept very well!
I try to remove <P> and </P>
Using this:
It does not generate any error, but does not work


// del <P> and </P> in IMG editor
$search = array (
'(<P>)',
'(</P>)'
);


$replace = array ('' );

$text = preg_replace($search, $replace, $thumb);

// end del P
 
I'm not a PHP expert, more of a talented user really, but I believe your patterns need to be formatted in perl format to use preg_ functions. Something like:
Code:
$search = array ('/(<P>)/', '/(<\/P>)/');

Additionally I believe you need to have the same number of array entries for the search and replace (though this is a guess):
Code:
$replace = array ('','');

-T

barcode_1.gif
 
Thanks Tarwn,
I think that you are on the right track
however, I am sorry to report that it did not do the trick.
 
Between Tarwn and my tweak I made it working
Use it to rem <P> generated by an img editor.
// del <P> and </P> in IMG editor

$search = array ('/<P>/', '/<\/P>/');

$replace = array ('','' );

$thumb = preg_replace($search, $replace, $thumb);

// end del P
 
but why are using preg_replace for this? seems like a sledgehammer to crack a nut - and it's really slow.

Code:
$correctedtext = str_replace (array("<p>","<P>","</p>","</P>"), ",", $uncorrectedtext);
 
Thanks, did not think about it, indeed simpler :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top