I want to retrieve the HTML code of a link (web page) in PHP. For example, if the link is
Cara Membuka Koneksi dengan Database MySQL PHP. PHP memiliki banyak fungsi berbeda yang telah built-in untuk manipulasi database. Berikut ini adalah fungsi-fungsi built-in, dan kita pasti akan menemukan ketika membuat aplikasi yang berhubungan dengan PHP dan MySQL. PHP in Visual Studio Code. Visual Studio Code is a great editor for PHP development. You get features like syntax highlighting and bracket matching, IntelliSense (code completion), and snippets out of the box and you can add more functionality through community-created VS Code extensions. PHP extensions.
then I want the HTML code of the page which is served. I want to retrieve this HTML code and store it in a PHP variable.
How can I do this?
Community♦
PrashantPrashant
12.3k59 gold badges151 silver badges212 bronze badges
9 Answers
If your PHP server allows url fopen wrappers then the simplest way is:
If you need more control then you should look at the cURL functions:
JerabekJakub
3,8092 gold badges19 silver badges28 bronze badges
GregGreg
262k48 gold badges342 silver badges321 bronze badges
Also if you want to manipulate the retrieved page somehow, you might want to try some php DOM parser.I find PHP Simple HTML DOM Parser very easy to use.
DmitriDmitri
You may want to check out the YQL libraries from Yahoo: http://developer.yahoo.com/yql
The task at hand is as simple as
You can try this out in the console at: http://developer.yahoo.com/yql/console (requires login)
Also see Chris Heilmanns screencast for some nice ideas what more you can do: http://developer.yahoo.net/blogs/theater/archives/2009/04/screencast_collating_distributed_information.html
IckmundIckmund
Simple way: Use
file_get_contents()
:
Please note that
allow_url_fopen
must be true
in you php.ini
to be able to use URL-aware fopen wrappers.
More advanced way: If you cannot change your PHP configuration,
Stefan GehrigStefan Gehrig
allow_url_fopen
is false
by default and if ext/curl is installed, use the cURL
library to connect to the desired page.
73.2k22 gold badges133 silver badges170 bronze badges
you could use file_get_contents if you are wanting to store the source as a variable however curl is a better practive.
this solution will display the webpage on your site. However curl is a better option.
devpro
14.4k3 gold badges22 silver badges36 bronze badges
piglotpiglot
look at this function:
![Sourde Code Koneksi Php Sourde Code Koneksi Php](/uploads/1/2/4/7/124725192/342738724.png)
2,6791 gold badge14 silver badges16 bronze badges
Here is two different, simple ways to get content from URL:
1) the first method
Enable Allow_url_include from your hosting (php.ini or somewhere)
or
2)the second method
Enable php_curl, php_imap and php_openssl
T.ToduaT.Todua
33.2k12 gold badges144 silver badges143 bronze badges
You can get the whole HTML code as an array (parsed form) using this codeDownload the 'simple_html_dom.php' file herehttp://sourceforge.net/projects/simplehtmldom/files/simple_html_dom.php/download
sarathsarath
you can use the DomDocument method to get an individual HTML tag level variable too
Krishnamoorthy AcharyaKrishnamoorthy Acharya
protected by Community♦Nov 3 '17 at 16:44
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?