hi i am trying to insert preg_match in IF statement after that replace it by preg_replace. So First ... if $post matching any image urls then replace it with (img src) else replace it with href ... $post = 'hello .. see that pic http://dogandcat.com/images/cat2.jpg and that pic http://www.helpinghomelesscats.com/images/cat1.jpg for more info plz click here http://google.com or here http://msn.com/music'; $pattrenlink='/((([http]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\/+=&#?;%@,.\w_]*)#?(?:[\w]*)?))/'; $pattrenimage='/(http(s?):)(.+)(?:jpg|jpeg|gif|png)/'; if (preg_match( $pattrenimage, $post)) { $html_links = preg_replace($pattrenimage, '<a href="$0" target="_blank" ><img src="$0" width="200" height="150"></a>', $post); } else { $html_links =preg_replace($pattrenlink, '<a href="$0" target="_blank">$0</a>', $post); } echo $html_links ; PHP: notice : all both regex work fine ... ( $pattrenlink macth any url) and ($pattrenimage match any image url).. (test it http://regexr.com?31sgg) but here it replace the image url only ??!! what i want is to replace the image with (img src= ) tags and replace url with href tags ??? so any help for $5 in paypal ?