הרשם שאלות ותשובות רשימת חברים לוח שנה הודעות מהיום

חזור   הוסטס - פורום אחסון האתרים הגדול בישראל > עיצוב גראפי, תכנות על כל שפותיו וקידום ושיווק אתרים > פורום תיכנות

   
|!|

השב
 
כלים לאשכול תצורת הצגה
ישן 05-02-09, 21:03   # 1
possible
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Feb 2008
הודעות: 121

possible לא מחובר  

עזרה| קוד שלא פועל

הקוד אמור לקבל את כל הקוד מקור של דף מסויים ואז הוא עובר על כל הקוד ברקורסייה ומציג את כל הקישורים שנמצאים בו.

PHP קוד:
<?php
$source 
file_get_contents("http://programart.co.cc/");
$linkpos1 strpos($source"<a ");

function 
getLinks($linkpos)
{
    
$targetpos=0;
    
$endtarget=0;
    if (
$linkpos!==false)
    {
        
$targetpos strpos($source"href=".'"',$linkpos+3);
        
$endtarget strpos($source'"',$targetpos+6);
        
$link substr($source$targetpos+6$endtarget-1); 
        echo 
$link."<br />"$targetpos+."<br />".$endtarget-1;
        
$linkpos strpos($source"<a ",$linkpos);
        
getLinks($linkpos);
    }
    else
    {    
        echo 
"Error";
    }    
}
getLinks($linkpos1+3);
echo 
$linkpos1;
?>
במקום לבצע את מה שרציתי הוא מציג את השגיאה:
Warning: strpos() [function.strpos]: Offset not contained in string in /home/devsys/domains/eyesharp.co.cc/public_html/check.php on line 11

Warning: strpos() [function.strpos]: Offset not contained in string in /home/devsys/domains/eyesharp.co.cc/public_html/check.php on line 12
5
Warning: strpos() [function.strpos]: Offset not contained in string in /home/devsys/domains/eyesharp.co.cc/public_html/check.php on line 15

ואני לא מבין למה הוא אומר לי שהארוך של הטקסט לא ארוך מספיק לאורך שהבאתי לו :O

תודה לעוזרים.

נ.ב הוא גם רושם Error בסוף.
__________________
תכנות אתרים

Last edited by possible; 05-02-09 at 21:07..
  Reply With Quote
ישן 05-02-09, 21:26   # 2
vadimg88
חבר מתקדם
 
מיני פרופיל
תאריך הצטרפות: Feb 2008
גיל: 37
הודעות: 710

vadimg88 לא מחובר  

אתה יכול לקבל את כל הקישורים מהעמוד בעזרת preg_match_all לא צריך פונקציה רקורסיבית.
  Reply With Quote
ישן 05-02-09, 22:11   # 3
Shon12
חבר מתקדם
 
מיני פרופיל
תאריך הצטרפות: Oct 2007
הודעות: 354

Shon12 לא מחובר  

^^כמו שוואדים אמר-preg_match_all:
PHP קוד:
<?php
$source 
file_get_contents("http://lasw.gamli.net/s.html"); 

    
preg_match_all("/\<a.+>(.+?)<\/a>/i",$source,$match);
    for (
$i 0$i <= strlen($match[0]); $i++)
    {
    echo 
$match[0][$i]."<br />";
    }
?>
__________________
Projector Lamps
  Reply With Quote
ישן 05-02-09, 22:12   # 4
possible
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Feb 2008
הודעות: 121

possible לא מחובר  

תודה רבה פועל.
אבל זה עדיין לא מציג לי את כל הקישורים שיש באותו עמוד.
נגיד מתי שהוא מציג של האתר programart.co.cc
הוא מציג רק את הקישורים האלה:
http://www.eyesharp.co.cc/check.php

אשמח גם להסבר קל איך הפונקצייה הזאת פועלת ^^
תודה רבה לכם
__________________
תכנות אתרים

Last edited by possible; 05-02-09 at 22:22..
  Reply With Quote
ישן 05-02-09, 22:32   # 5
Shon12
חבר מתקדם
 
מיני פרופיל
תאריך הצטרפות: Oct 2007
הודעות: 354

Shon12 לא מחובר  

PHP קוד:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<?php
$source 
file_get_contents("http://programart.co.cc"); 

    
preg_match_all("/\<a.+>(.+?)<\/a>/i",$source,$match);
    foreach(
$match[0] as $value)
    {
    echo 
$value."<br />";
    }
?>
דוגמא:
http://lasw.gamli.net/s.php
http://il.php.net/preg_match_all

תהנה
ואין בעד מה
__________________
Projector Lamps
  Reply With Quote
ישן 05-02-09, 22:58   # 6
Elad-A
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 1,987

Elad-A לא מחובר  

יש פונקצייה שנכתבה ע"י The AcE :

PHP קוד:
function getLinks ($file) {
    
$ur=parse_url($file);            #parsh the URL
    
$data=file_get_contents($file);    #get the file from the server
    
$regex="/<a.*href=[\"']?([^\"' >]+)[\"' >](.*)<\/a>/imsU";
    
preg_match_all($regex,$data,$matches,PREG_SET_ORDE  R);
    
$_ins=array(); $_outs=array();
    
$_ins[]=trim($ur['path'],"/");
    foreach (
$matches as $match) {
        
$purl=parse_url($match[1]);
        if ((    
#check if it is an inner link
                
($purl['host']    == $ur['host'] and $purl['scheme'] == 'http')
            or    (!
$purl['host'] and !$purl['scheme']))        #check if has host (for when href is: 'javascript' then scheme is 'javascript' and no host set)
            
and    !in_array(trim($purl['path'],"/"),$_ins)    #check if not in our array, we don't need duplicated addresses
            
) {
            
$ins[]=array('text'=>$match[2],'href'=>trim($purl['path'],"/"));
            
$_ins[]=trim($purl['path'],"/");
            continue;
        } elseif (
                
$purl['host'] != $ur['host']    #check that it is actually an outgoing link
            
and    !in_array(ltrim($match[1],"/"),$_outs#check if not in our array to avoid duplicated links
            
and    $purl['scheme'] == "http"         #get only the http links
            
) {
            echo 
"Putting in outs.\n";
            
$outs[]=array('text'=>$match[2],'href'=>ltrim($match[1],"/"));
            
$_outs[]=ltrim($match[1],"/");
            continue;
        }
    }
    return array(
'outs'=>$outs,'ins'=>$ins);

הפונקצייה מחזירה פלט בצורה של קישורים נכנסים \ יוצאים מהדף, כמובן שכל הקרדיט הולך אליו כן?
  Reply With Quote
השב

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 


חוקי פירסום
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 מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 13:54.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ