Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

PHP: Get the contents of a web page, RSS feed, or XML file into a string variable PHP: קבל את תוכנו של דף אינטרנט, עדכון RSS, או קובץ XML לתוך משתנה מחרוזת

You will often have the need to access data that resides on another server, whether you are writing an online RSS aggregator or doing screen scraping for a searching mechanism. אתה לעתים קרובות יש צורך בגישה לנתונים הנמצא בשרת אחר, אם אתה כותב צובר RSS מקוונים או עושה מסך גירוד עבור מנגנון חיפוש. PHP makes pulling this data into a string variable an extremely simple process. PHP עושה זה מושך נתונים למחרוזת משתנה תהליך מאוד פשוט.

You can go with the really short method: אתה יכול ללכת עם השיטה ממש קצר:

$url = “http://www.howtogeek.com”; $ url = "http://www.howtogeek.com";

$str = file_get_contents($url); $ str = file_get_contents ($ url);

The only problem with that method is that some web hosts have url access blocked in the file methods, for security reasons. הבעיה היחידה עם השיטה היא כי חלק המארחים באינטרנט יש גישה url חסם בשיטות הקובץ, מסיבות ביטחוניות. You may be able to use this workaround method instead: ייתכן שתוכל להשתמש בשיטה זו לעקיפת הבעיה במקום:

 function get_url_contents($url){ get_url_contents פונקציה ($ url) ( 
         $crl = curl_init(); CRL $ = curl_init (); 
         $timeout = 5; $ timeout = 5; 
         curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($ CRL, CURLOPT_URL, $ url); 
         curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ CRL, CURLOPT_RETURNTRANSFER, 1); 
         curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ CRL, CURLOPT_CONNECTTIMEOUT, $ timeout); 
         $ret = curl_exec($crl); ret $ = curl_exec ($ CRL); 
         curl_close($crl); curl_close ($ CRL); 
         return $ret; return $ ret; 
 } ) 

You should now have the contents of the website in a string variable. כעת אתה אמור להיות התוכן של האתר משתנה מחרוזת. Note that this doesn't pull down the supporting files such as javascript or CSS. שים לב כי זה לא מורידים את הקבצים כגון תמיכה ב CSS או JavaScript. You will have to further parse the page and retrieve those seperately if you need the whole thing. תצטרך להמשיך לנתח את הדף ואת לאחזר אותם בנפרד אם אתה צריך את כל העניין.

This article was originally written on 09/25/06 Tagged with: מאמר זה נכתב במקור ב 09/25/06 עם שתייגת: PHP PHP , , Programming תכנות

Daily Email Updates שערי עדכונים בדוא"ל

You can get our how-to articles in your inbox each day for free. אתה יכול לקבל כמה שלנו למאמרים לתיבת הדואר שלך בכל יום בחינם. Just enter your name and email below: פשוט להזין את שם ואת הדוא"ל שלך להלן:


Name: שם:
Email: דואר אלקטרוני:

Comments (4) תגובות (4)

  1. Demetrius Demetrius

    Problem with RSS Feed in WordPress. בעיה עם RSS Feed ב-WordPress.
    I have a subdomain that I installed wordpress for another blog site, but the subdomain site's rss feed points to my parent site. יש לי משנה כי התקנתי WordPress בלוג באתר אחר, אבל האתר משנה של נקודות Feed RSS לאתר ההורים שלי.
    Can anyone come up with any suggestions? האם מישהו יכול לבוא עם הצעות כלשהן?

  2. Davide Davide

    Hi, הי,

    I've tried your hack but I always get the same result: ניסיתי לפרוץ שלך אבל אני תמיד מקבל את אותה תוצאה:

    “Destination host forbidden” "אסור לארח יעד"

    How can I solve this issue? איך אני יכול לפתור בעיה זו?

    Thanks. תודה.

  3. ypi prem Prem ypi

    Thanks a lot for your simple function. תודה רבה על פונקציה פשוטה שלך. This really gives a lot of power to user to reuse the internet! זה באמת נותן המון כוח למשתמש לעשות שימוש חוזר לאינטרנט!
    Ofcourse the content should be pulled with prior approval! ודאי התוכן צריך להיות משך עם אישור מראש!

  4. anonymous אנונימי

    i love u! U אני אוהבת!


Leave a Comment השאירו תגובה




Leave your השאירו שלך friendly ידידותי comment here. תגובה כאן.

If you have a computer help question, אם יש לך מחשב לעזור השאלה, click here to leave it on the forums לחץ כאן כדי להשאיר אותו על פורומים instead. במקום.

Note: Your comment may not show up immediately on the site. הערה: ההערה שלך לא תופיע מיד באתר.

Our Friends חברים שלנו
Getting Started התחלת העבודה


About How-To Geek אודות How-To Geek
What Is That Process? מה זה תהליך?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe Ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. זכויות יוצרים © 2006-2009 HowToGeek.com. All Rights Reserved. כל הזכויות שמורות.