1

I have parser which parsing urls.

In some parsed urls I have a simple space like %20, but if I check the real url of parsed site I see this non-breaking space %C2%A0.

So, how I can replace %20 to %C2%A0?

foreach($productUrls as $href) {
   $productWithSpace = str_replace('%20', '%C2%A0', $href['url']);
   $link = 'http://optnow.ru/' . $productWithSpace;
   $product = file_get_html($link);
}

But It still not working.

Where is my mistake?

Thanks

Frunky
  • 385
  • 1
  • 6
  • 14

1 Answers1

0

What I believe you are asking for

urlencode transforms spaces into '+'s, but if you want them to be %20, you can use rawurlencode to get around that.

$productWithSpace = rawurlencode(urldecode($href['url']));
$link = 'http://optnow.ru/' . $productWithSpace;
$product = file_get_html($link);

I would use

urldecode($string)

It will decode any urls automatically for you. Less chance for user mistake. Additionally, it decodes things you might not know needs to be decoded.

So, your new code would be (and this should fix your problem):

$productWithSpace = urldecode($href['url']);
$link = 'http://optnow.ru/' . $productWithSpace;
$product = file_get_html($link);
Neil
  • 14,063
  • 3
  • 30
  • 51