Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Need Some Help - Arrays, Foreach, Newbie stuff...


[SOLVED] Need Some Help - Arrays, Foreach, Newbie stuff...

Reply
  #1 (permalink)  
Old 12-22-08, 01:01 PM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Need Some Help - Arrays, Foreach, Newbie stuff...

Ive made this little script and Im stuck on a few of the basic bits

Basically what this script does is fetches the <head> and <body> of an array of pages. But its not, to put it simply.

Could someone take a look and tell me what Im doing wrong. I think I need to use foreach () somewhere but Im not too sure.

PHP Code:

<?php


$req_url 
= array('http://www.first.com''http://www.second.com''http://www.third.com');

function 
get_head($a,$b,$c){ // Gets a string between 2 strings
        
$y explode($b,$a);
        
$x explode($c,$y[1]);
        return 
$x[0];
    } 

function 
get_body($a,$b,$c){ // Gets a string between 2 strings
        
$y explode($b,$a);
        
$x explode($c,$y[1]);
        return 
$x[0];
    }

//Get head
echo get_head(file_get_contents('$req_url'), '<head>''</head>');

//Gets body
echo get_body(file_get_contents('$req_url'), '<body>''</body>');
 

?>
Thanks
__________________
Free Online Movies
Reply With Quote
  #2 (permalink)  
Old 12-22-08, 01:23 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
$y should = 0 not 1 - EDIT: scrap that I see what you've done now sorry
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #3 (permalink)  
Old 12-22-08, 01:31 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
$req_url should be passed as an array and not as a string

use this instead;

PHP Code:

//Get head
echo get_head(file_get_contents($req_url[0]), '<head>''</head>');

//Gets body
echo get_body(file_get_contents($req_url[1]), '<body>''</body>'); 
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #4 (permalink)  
Old 12-22-08, 01:46 PM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
That solves some problems but it still doesnt show 3 pages. Just the one :|
__________________
Free Online Movies
Reply With Quote
  #5 (permalink)  
Old 12-22-08, 01:49 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
replace the last 2 lines of code with this;

PHP Code:


foreach($req_url as $val){
    if(
$val != "")echo get_head(file_get_contents($val), '<head>''</head>');

Kind Regards
Dal
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #6 (permalink)  
Old 12-22-08, 04:18 PM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Great. That worked perfectly. Thanks again
__________________
Free Online Movies
Reply With Quote
  #7 (permalink)  
Old 12-22-08, 06:12 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Cool! can you mark this as "solved" from the thread tools thanks

Dal
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
work on arrays within arrays - i'm stuck... nassau PHP 1 04-29-06 02:37 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Foreach Variable/array Scope DAL PHP 5 10-22-05 01:38 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 08:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.