scbookz Posted July 29, 2009 Share Posted July 29, 2009 i dont get error codes i just get a blank page what i am trying to get is the string content of the <head> tag what i want is <head>i want this part to show</head> ---output page---> i want this part to show --------------------------------------------------------------------------------------- nothing is showing on my out put page just a blank screen not even the word array is showing now --------------------------------------------------------------------------------------- <?php $html = file_get_contents("http://webpage.html"); $file = file_get_contents("http://webpage.html"); $x = (get_doc_title($file)); print_r($res[0]); print_r($res[1]); print_r($res[2]); // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all("/(?<=Purpose<head>).+?(?=<\/head>)/", $html, $patterns, PREG_PATTERN_ORDER); $res = array(); } ?> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/ Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 There isn't a syntax issue... display php errors and see what you learn. Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886267 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 no errors show up there are no errors on the output page it is just a blank page it refers to a html page that has tags and nothing is showing up on the page i am new to php programing but the error codes went away wheni made this code but the array output left also Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886279 Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 There are few logic issues here: You're calling $res outside of the function scope, so the variable doesn't actually exist. You're $html variable isn't being used. You're trying to print an array where I assume you actually want to echo html. Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886289 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 ok i did as the guy said here is what errors showed up Notice: Undefined variable: html in /var/www/net/helllooo.php on line 23 Notice: Undefined variable: res in /var/www/net/helllooo.php on line 15 Notice: Undefined variable: res in /var/www/net/helllooo.php on line 16 Notice: Undefined variable: res in /var/www/net/helllooo.php on line 17 23 $h1tags = preg_match_all("/(?<=Purpose<head>).+?(?=<\/head>)/", $html, $patterns, PREG_PATTERN_ORDER); lines 15 16 17 print_r($res[0]); print_r($res[1]); print_r($res[2]); Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886292 Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 Which makes sense because those variables are all out of scope (separated by the function). Are you actually trying to do something like this?: <?php $file = file_get_contents("http://webpage.html"); $x = (get_doc_title($file)); echo $x; // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all("/(?<=Purpose<head>).+?(?=<\/head>)/", $file, $patterns, PREG_PATTERN_ORDER); return $h1tags; } ?> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886297 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 yes let me try this but $patterns is still left out of the picture not sure what that variable is for i willtry that now brb Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886306 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 ok something seemed to work but my output is = 0 i only show a zero i want the string between the tags thanks mark Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886311 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 my new code with output of zero ( 0 ) the tagi am trying to grab text from is this <title>Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region)</title> -------------------------------------------- <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $file = file_get_contents("http://xxxxxxxxxx.html"); $x = (get_doc_title($file)); echo $x; // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all("/(?<=Purpose<title>).+?(?=<\/title>)/", $file, $patterns, PREG_PATTERN_ORDER); return $h1tags; } ?> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886313 Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 If that preg_match_all did return a zero it means that it did not find any occurances of this particular pattern. Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886316 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 the tagi am trying to grab text from is this <title>Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region)</title> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886318 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 oh ok maybe i was not clear i am trying to print the information between the tags the html page has a title but i want to grab the string between the title on the source page and then print is in my output you get a free book if this works Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886320 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 here is the html code from the page i am trying to grab from <HTML> <HEAD> <title> Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region)</title> <meta name="Description" content="Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region), ISBN 1569520011, "> <meta name="Keywords" content="1569520011, Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region), compare book prices, book price comparison"> <meta content="index,follow" name="Robots"> </HEAD> i am trying to grab the string between tags and not anoutput of if it finds or not i hope i am making myself clear on this Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886322 Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 Not really expert on regular expressions but you could try this <?php preg_match_all('/<title>(.*)<\/title>/', $html, $matches, PREG_PATTERN_ORDER); var_dump($matches[1][0]); ?> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886325 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 crazyyyyyy very good man getting closer here is my output now --------------------------------------------- string(190) " Switzerland and the Alpine Region, 1994: The Most In-Depth Guide to the Beauty and Majesty of Switzerland and the Alpine Region (Fielding's Switzerland and the Alpine Region)" ----------------------------------------------------------------------------- how do i get rid of the string(190) comment? Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886340 Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 Yeah well the var_dump() -function is a good tool to debug your code and it will print the type of the variable, in this case it is string, length of the string and the string itself. So you have to put the match found by the regexp into variable or echo or do whatever you want with it.. <?php $myVariable = $matches[1][0]; echo $myVariable; Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886348 Share on other sites More sharing options...
scbookz Posted July 29, 2009 Author Share Posted July 29, 2009 i found something better that works thanks to your help but my last thing is to use a minus in echo i have set words i want to subtract out of an echo statement i will need to research this and then i am done ---------------------------------------------------------------------- echo $x-(a word phrase) not sure if i can do this but has to be a way ----------------------------------------------------- $file = file_get_contents("http://website.html"); $x = (get_doc_title($file)); echo $x; // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all('/<title>(.*)<\/title>/', $file, $matches, PREG_PATTERN_ORDER); var_export($matches[1][0]);} ?> Link to comment https://forums.phpfreaks.com/topic/168041-whats-wrong-with-this-code-it-shows-a-blank-page-only/#findComment-886363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.