GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php Help needed... (https://gfy.com/showthread.php?t=204881)

4Pics 12-05-2003 02:30 AM

Php Help needed...
 
Can someone share some code that will grab from a webpage all a href's and img's on the page? Also how to grab a certain text string out of a webpage.

Thanks

Alky 12-05-2003 02:31 AM

http://www.php.net/manual/en/function.preg-grep.php

Why 12-05-2003 02:32 AM

php.net is where all questions about php are answered. much better place to seek answers then GFY.

fletcher 12-05-2003 02:36 AM

I'll be nice and share one regexp :)

This grabs all linked images on a page:

PHP Code:

/<a.*href=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><img.*src=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><\/a>/im 

In PHP, do it like this:

PHP Code:

preg_match_all("/<a.*href=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><img.*src=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><\/a>/im"$string$matches

$matches is an array with all of the images with links. Just change up the regexp for plain links, images, etc.

swedguy 12-05-2003 02:37 AM

http://zend.com/codex.php?id=231&single=1

4Pics 12-05-2003 11:16 AM

Quote:

Originally posted by fletcher
I'll be nice and share one regexp :)

This grabs all linked images on a page:

PHP Code:

/<a.*href=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><img.*src=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><\/a>/im 

In PHP, do it like this:

PHP Code:

preg_match_all("/<a.*href=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><img.*src=[\"|\']([^\"|^\'|^\s]+)[\"|\'].*><\/a>/im"$string$matches

$matches is an array with all of the images with links. Just change up the regexp for plain links, images, etc.

Thanks, but is your top link correct? It looks like it is cutoff?


All times are GMT -7. The time now is 11:24 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123