Jump to content

whats wrong with this code it shows a blank page only


scbookz

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.