PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Fri Feb 24, 2006 3:16 pm
I am trying to catch values in this line.
Code: Select all
<a href="javascript: void(0);" id="ctl00__MessageFriendLink" onclick="javascript: up_myfunction( '1234567', '222222', '', 0 ); return false;">
I only want to catch the information "1234567" here is what I have and what I'm using.
Code: Select all
preg_match("/up_myfunction( '([0-9])'/", $contents, $matches);
Any help would be greatly appriciated!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 24, 2006 3:30 pm
add a plus immediately following the closing bracket (]) inside the parentheses.
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Fri Feb 24, 2006 3:39 pm
I now have this
Code: Select all
preg_match("/up_myfunction( '[0-9]+'/", $contents, $matches);
And I get this error.
Code: Select all
Warning: Compilation failed: missing ) at offset 21 in /home/www/www.mydomain.com/mypage.php on line 9
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 24, 2006 4:06 pm
put a backslash before the first opening paren inside the string.
Code: Select all
preg_match("/up_myfunction( '[0-9]+'/", $contents, $matches);
// ^You'll need to put the parentheses around the [0-9]+ if you want the number..
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Fri Feb 24, 2006 5:16 pm
Thats what I have and it seems like Im still getting an error.
Code: Select all
Warning: Compilation failed: missing ) at offset 21 in /home/www/www.mydomain.com/mypage.php on line 9
SKDevelopment
Forum Newbie
Posts: 13 Joined: Thu Jan 26, 2006 10:42 am
Post
by SKDevelopment » Fri Feb 24, 2006 5:29 pm
Code: Select all
<?php
$contents = <<<CONT
<a href="javascript: void(0);" id="ctl00__MessageFriendLink" onclick="javascript: up_myfunction( '1234567', '222222', '', 0 ); return false;">
CONT;
preg_match("/up_myfunction\(\s*'([0-9]+)',/", $contents, $matches);
echo $matches[1];
?>
--
Best Regards,
Sergey Korolev
www.skdevelopment.com
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Fri Feb 24, 2006 6:50 pm
Thanks for all the help. This is really starting to make sense to me.
Now my script is being ran from another site. How can I have $contents equal to the text that is loaded from the page that is calling it? I tried this but it doesn't seem to be working.
Code: Select all
$ch = curl_init();
$timeout = 3;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 24, 2006 7:32 pm
What doesn't seem to be working? Not to sound condescending, but did you forget to echo $contents?