Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-25-2005, 03:24 PM Regex Question
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi everyone.

I am looking through a web-page for important data which looks like this:

<a href="UniqueBeginWord.php?d=important data">UniqueEndWord</a>

I have been beating my head trying to recycle a regex to extract it, but it's not working.

Can anyone with experience in regex give me a hand trying to extrac the important data?

Note: important data contains the following: letters, numbers, colon marks (i.e. , less than sign (i.e. <) and more than sign (i.e. >).

Sample:
PHP Code:
$string '<a href="UniqueBeginWord.php?d=first word;;408<br>second word;;409<br>third and fourth words;;461<br>fifth word;;156<br>last word;;212'>UniqueEndWord</a
Thanks.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 04-25-2005, 04:56 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
This seems to work, correct me if I'm wrong.
PHP Code:
<?php

$url
='<a href="Lumberjack.php?d=one<br>;;two<br>;;318">NorwegianBlue</a>';
$matches=Array();
$regex="#<a href=\"Lumberjack.php\?d=(.*?)\">NorwegianBlue#";

echo 
preg_match($regex,$url,$matches);
echo
"<br />";
echo
"<pre>".$matches[0]." ".$matches[1]."</pre>";

?>
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-25-2005, 05:06 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi 0beron.

It works fine if the data is hardcoded, but when call the file remotely like this

$file = file_get_contents($url);

It doesn't. Any idea?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 04-25-2005, 05:36 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
This is a wild guess - is it choking on html entities? By that I mean file_get_contents() gives you &gt; when you were expecting > ? I don't know quite how the get contents function behaves.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-25-2005, 05:40 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
I agree with you that it is chocking on something.

Even when i try

$response = file_get_contents($url);
$position = strpos($reponse, "keyword");

I get nothing.

Do you know a known way of opening up a remote web page and then doing what we want to do?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 04-25-2005, 05:56 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
OK. I got SOMETHING to work.

It might not be as beautiful as a regex, but it works
$result = file_get_contents($url);
$begin = strpos ($result, "firstword");
$finish = strpos ($result, "endword");
$results = substr ($result, $begin, ($finish-$begin));

Thanks.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Regex Question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25122 seconds with 12 queries