Question: i got Source Code From Remote Url Like This 

```
$f = file_get_contents("http://www.example.com/abc/");
$str=htmlspecialchars( $f );
echo $str;

```

in that code i want to replace/extract any url which is like 

```
href="/m/offers/"

```

i want to replace that code/link as 

```
href="www.example.com/m/offers/"

```

for that i used

```
$newstr=str_replace('href="/m/offers/"','href="www/exmple.com/m/offers/',$str);
echo $newstr;

```

but this is not replacing anything now i want to know 1st ) can i replace by str\_replace ,in the code which is fetched from remote url and if 'yes' how ...? if 'no' any other solution ?

Answer: 
There will not be any `"` in your `$str` because `htmlspecialchars()` would have converted them all to be `&quot;` before it got to your `str_replace`.
I start assuming all href attributes belong to tags.

Since we know if all tags are written in the same way. instead of opting for regular expressions, I will use an interpreter to facilitate the extraction process

```
<?php

use Symfony\Component\DomCrawler\Crawler;

$base = "http://www.example.com"
$url = $base . "/abc/";

$html = file_get_contents($url);

$crawler = new Crawler($html);

$links = array();
$raw_links = array();
$offers = array();

foreach($crawler->filter('a') as $atag) {
  $raw_links[] = $raw_link = $atag->attr('href');
  $links[] = $link = str_replce($base, '', $raw_link);  
  if (strpos($link, 'm/offers') !== false) {
    $offers[] = $link;
  }

}

```

now you have all the raw links, relative links and offerslinks

I use the [DomCrawler component](http://symfony.com/doc/current/components/dom_crawler.html)