Help - Search - Members - Calendar
Full Version: Regex help needed urgent
Invision Power Services > Community Forums > Community Web Design and Coding
Zainzz
Hello,
I need to come up with a solution where a php script will open connection to a webpage and will return success message if a particlar code snippet is found on that webpage.
Here's the code snippet i'd likely be searching for in the webpage:
CODE
<script type="text/javascript" src="[url="http://www.abc.com/fetchlinks.php?id=1"]http://www.abc.com/fetchlinks.php?id=1[/url]">
</script>


I want to search this code snippet throughout that webpage and return successfull message if it succeeds. I think i'll have to use regex for matching this? Can anybody please help me with this, i'm stuck.

Thanks
NOW
I think I don't understand the problem...

maybe you should try using preg_match()
Dimdum
I'm not sure it's possible...
To make php script open connection to a webpage, and to make it return messege on success. I'm not sure about the ability of PHP to do it as a server-side languge.
Rikki
Personally I've never tried this before, but you might be able to do it with fopen() if your host allows the URL wrapper for file functions, or you could use curl() to open it (if your PHP has it installed, I'm not sure it's compiled by default).
NOW
QUOTE(Dimdum @ Apr 27 2006, 12:33 AM) *
I'm not sure it's possible...
To make php script open connection to a webpage, and to make it return messege on success. I'm not sure about the ability of PHP to do it as a server-side languge.


It's possible...
Zainzz:

you can do something like this:

CODE
$txt = preg_replace( "#<script type=\"text/javascript\" src=\"\[url=(.+?)\](.+?)\[/url\]\"</script>#is", "URL: \\1, WORDS: \\2", $txt );


if that's what you need...
Dimdum
He wants to open connection to a webpage, and you gave him preg function...
Zainzz
I'm sorry if I didn't make it clear. I know how to open a connection to the server and wanted the steps ahead i.e. how to search (preg_match) using regex that the code snippet EXISTS on that webpage. I guess i'll be using NOW's code snippet biggrin.gif ... I'll let you know if it worked

Thanks for helping biggrin.gif
Zainzz
Can i get the preg_match version of the preg_replace code above please? so that i can match if such a thing is on the webpage?


and my bad.. the actual code i wanted to match was:
<script type="text/javascript" src="http://localhost/fetchlinks.php?id=1">
</script>
Dimdum
preg_replace:
CODE
$txt = preg_replace( "#<script type=\"text/javascript\" src=\"(.+?)\"</script>#is", " \\1", $text );
preg_match (directly from the script withot the $txt var)
CODE
$match = preg_match( "#<script type=\"text/javascript\" src=\"(.+?)\"</script>#is", $text );
and preg_match that you can use after the first code:
CODE
$match = preg_match( "#".$txt."#is", $var );
$match can be 'TRUE' or 'FALSE' only...
Zainzz
aah.. thanks a lot...
this is what i'm finally using
CODE
preg_match("#<script type=\"text/javascript\" src=\"(.+?)\">\s*?</script>#i", $url, $match)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.