Jump to content

[SOLVED] preg match URL and Image


9three

Recommended Posts

I'm grabbing information from a site. I only need two things from there.

 

1. the URL so the image can show up

2. the image path

 

heres what I got so far

 

<?php

$gold = file_get_contents('http://www.site.com/');
preg_match('~http://www.site.com/~is', $gold, $url);
preg_match('~<span id = "XAU_B">(.+?)</span>~is', $gold, $goldMatch);

for ($i = 0; $i < 1; $i++)
  echo $url[$i].$goldMatch[$i];

?>

 

The output and problem:

 

http://www.site.com/<span id = "XAU_B"><img src="tbdfc/freeprice.aspx?id=25632d3e-b712-9638-8029-8ffc3b112b3b&nolog=true" id="i_XAU_B"></span>

 

Basically what I'm trying to do is

 

<span id = "XAU_B"><img src="http://www.site.com/tbdfc/freeprice.aspx?id=25632d3e-b712-9638-8029-8ffc3b112b3b&nolog=true" id="i_XAU_B"></span>

 

 

Link to comment
https://forums.phpfreaks.com/topic/145527-solved-preg-match-url-and-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.