Connecting Tech Pros Worldwide Forums | Help | Site Map

Attempting* to use reg exp. Guidance needed O:)

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,939
#1: Feb 8 '08
So, i'm making a proxy, cos, well, i'm bored. I thought it'd be rather easy actually.. but alas, it requires reg exp's - one of my pet hates; just below class's.

Anyway, the code im using:
[php]
$_string = file_get_contents("http://myspace.com"); // myspace file.

$_reg = '#\"http://(.*)\"#'; // regular expression

preg_match($_reg, $_string, $_match);
echo htmlentities($_match[0]);
[/php]
This works... but it gives me this:
Expand|Select|Wrap|Line Numbers
  1. "http://x.myspacecdn.com/Modules/Common/Static/img/iphone.png" /><meta http-equiv="expires" content="0" /><meta http-equiv="Pragma" content="no-cache"
  2.  
when what i actually want is:
Expand|Select|Wrap|Line Numbers
  1. "http://x.myspacecdn.com/Modules/Common/Static/img/iphone.png"
  2.  
It stretches to the last quote on the current line.. when i want the first quote that comes after href=

Any ideas?

Newbie
 
Join Date: Mar 2008
Posts: 14
#2: Mar 30 '08

re: Attempting* to use reg exp. Guidance needed O:)


Instead of matching with .*, you could match with [^\"]*. That way you will only match until first occurence of \".
Expand|Select|Wrap|Line Numbers
  1. $_reg = '#\"http://([^\"]*)\"#'; // regular expression
Reply