काफी सरल, इस कोड को मैंने आपके लिए बनाया है।
डीबी में स्रोत को पकड़ने और सहेजने की मूल बातें हैं।
मैं त्रुटि हैंडलिंग डाल नहीं था या जो कुछ भी है, बस उसे पल के लिए सरल रखने ...
मैं परिणाम दिखाने के लिए समारोह बना नहीं था, लेकिन आप देखना $ स्रोत मुद्रित कर सकते हैं परिणाम।
आशा है कि यह आपकी मदद करेगा।
<?php
function GetPage($URL)
{
#Get the source content of the URL
$source = file_get_contents($URL);
#Extract the raw URl from the current one
$scheme = parse_url($URL, PHP_URL_SCHEME); //Ex: http
$host = parse_url($URL, PHP_URL_HOST); //Ex: www.google.com
$raw_url = $scheme . '://' . $host; //Ex: http://www.google.com
#Replace the relative link by an absolute one
$relative = array();
$absolute = array();
#String to search
$relative[0] = '/src="\//';
$relative[1] = '/href="\//';
#String to remplace by
$absolute[0] = 'src="' . $raw_url . '/';
$absolute[1] = 'href="' . $raw_url . '/';
$source = preg_replace($relative, $absolute, $source); //Ex: src="/image/google.png" to src="http://www.google.com/image/google.png"
return $source;
}
function SaveToDB($source)
{
#Connect to the DB
$db = mysql_connect('localhost', 'root', '');
#Select the DB name
mysql_select_db('test');
#Ask for UTF-8 encoding
mysql_query("SET NAMES 'utf8'");
#Escape special chars
$source = mysql_real_escape_string($source);
#Set the Query
$query = "INSERT INTO website (source) VALUES ('$source')"; //Save it in a text row, that's it...
#Run the query
mysql_query($query);
#Close the connection
mysql_close($db);
}
$source = GetPage('http://www.google.com');
SaveToDB($source);
?>
कोड के लिए बहुत बहुत धन्यवाद। मुझे एक स्वरूपित वेब पेज को सीएसएस और चित्रों के साथ स्टोर करने की आवश्यकता है, इसलिए जब मैं इसे गूंजता हूं, तो परिणाम मूल रूप से स्वरूपित वेब पेज होगा। मैं ऊपर दिए गए कोड का धन्यवाद नहीं करता हूं। कृपया मुझे सुधारें अगर मैं गलत हूं। – codemaker
हां यह होगा, इसे स्वयं आज़माएं, उपयोग करें: गूंज प्राप्त करें ('http://www.google.com'); आप समान पृष्ठ को Google के रूप में देखेंगे। यदि आप जो चाहते हैं वह नहीं है, तो मुझे आपका अनुरोध समझ में नहीं आया ... – geek1983
क्षमा करें, GetPage ('http://www.google.com') गूंजें; – geek1983