Page 1 of 1

regex trouble... please help!

Posted: Sun Feb 13, 2011 9:05 pm
by robertbarzyk
<img src="http://c3.ac-images.myspacecdn.com/imag ... 6d9932.jpg" class="profilePic" alt="Photo of ıł♥νeчøυ(:" />


I NEED to use preg_match for this...
The img src will be different everytime and so will the alt.
here is the code i have so far but i cant seem to get it right... the only piece of info i need out of the string above is the img src
but once again... i need to find in with preg match in that certain string. please and thanks for any help


$fid = 178902;
$getfid = $fid;
$ip = $_SERVER['REMOTE_ADDR'];

define ("getFID","http://www.myspace.com/" );
$path = getFID.$getfid;
$holdID = file_get_contents($path);

define ("profile_url","http://mx.myspace.com/" );
$full_file_path = profile_url.$fid;
$handle = fopen("http://myspace.com/$fid","r");
if (!$handle){
echo "<p>Sorry Myspace Is Slow Try Again.\n";
$arr = 0; }
else {
$timeout = 300;
ini_set('max_execution_time','120');
set_time_limit(120);
ini_set('default_socket_timeout','120');
while($contents = fread($handle,'1024'))
{ $hold .= $contents; }


preg_match("<img src=\"([^\">]+)\" class=\"profilePic\" alt=\".*?\" />",$hold,$match);

Re: regex trouble... please help!

Posted: Tue Feb 15, 2011 2:17 pm
by tr0gd0rr
Try putting a tilde around your string. PHP needs to see a delimiter (usually a slash but you have a slash in your regex) Also, add parentheses to capture the alt value. You may also want to take into consideration html with uppercase tag or attribute names, single quotes instead of double or without the self-closing slash.