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
how to extract urls from src=
Old 05-14-2008, 08:02 PM how to extract urls from src=
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
hi all,

okay so im making a img check function.

how can i get the url from src?

i will input all code into function i want it to get the url will run file_exists on it if it does leave it if not replace it with a default not found image

So how can it be done?

TP for the people with helpful replies
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 05-14-2008, 08:17 PM Re: how to extract urls from src=
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Via a DOMdocument:
PHP Code:
function getPage($url="http://www.example.com/"){
    
$ch curl_init();
    
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
    
curl_setopt($ch,CURLOPT_URL$url);
    
curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE);
    
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,15);
    
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    
curl_setopt($ch,CURLOPT_REFERER,'http://www.google.ch/');
    
curl_setopt($ch,CURLOPT_TIMEOUT,30);
    
curl_setopt($ch,CURLOPT_USERAGENT$useragent);
    
//curl_setopt($ch,CURLOPT_RANGE,0-4096);
    
$html=curl_exec($ch);
    
curl_close($ch);
    return 
$html;
}

function 
getLinks($url){
    
//Fetch a page HTML via curl
    
$html=getPage($url);
    
    
$dom=new DOMDocument();

    
//As I load HTML, I'm not sure it's valid, so I clean it up via tidy first
    
$tidy = new tidy;
    
$tidy->parseString($html);
    
$tidy->cleanRepair();
    
$html=$tidy->value;

    
$html=tidy_repair_string($html);
    
$ret=$dom->loadHTML($html);
    
    
//And now we parse our HTML the DOM way
    
foreach($dom->getElementsbytagname('a') as $k=>$n){
        
$href=$n->getAttribute('href');
        if(
strpos($href,'http')===0){
            
$aryLnk[$href]=1;
        }
    }
    
    foreach(
$aryLnk as $href=>$junk){
        echo
"I will grab <a href=\"$href\">$href</a>:<br>";
        echo<<<html
            <img src="http://web-screenshots.com/free/$href" title="$href"/><hr>
html;
    }

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-14-2008, 08:36 PM Re: how to extract urls from src=
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
confused how would that replace it if its not working

i get confused easily when its 00:36
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to how to extract urls from src=
 

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.11603 seconds with 12 queries