Aditya Pandey Aditya Pandey - 5 months ago 14x
PHP Question

Remove url from string but leave data in it by php

I have tried for it. But I could not do that, Here is my code

$p = '|<a [^>]*href="http://<some url>[^"]*"[^>]*>.*</a>|iU';

preg_replace($p, '$1', $a);

From above code I get all the link from that text, except the specific url. I want to get all the data in between link tag. Thats all.

Here is the link

<a href="http://<some url>"> <img src="Some url" alt="DZJarAP" width="213" height="300"></a>

I want it to be like

<img src="http://<some url>" alt="DZJarAP" width="213" height="300">

It may be any tag like img,p,div

Please help me out. Your answer are highly appreciable


You can do this work using preg_match like this

preg_match("/^(<.*?>)(.*)(<.*?>)$/", $HTML, $matchs);
$imgsTag = $matchs[2];

It return every tag in <a>.