Jump to content

trying to preg_match text from another page


Jnerocorp

Recommended Posts

this is what I tried:

 

<?php

			        function getText () {
            $url = "www.tizag.com";
            $data = getPage($url);
            preg_match('#<td class="mainIn"><h1>Welcome to Tizag Tutorials</h1>
<p>([a-z0-9,]+)</p><br>	</td>#si', $data, $p);
       	   } //This is line 11
	?>
	This will get the main text from the site Tizag.com<br>
	<br>
	<?php echo getText(); ?>

 

this is the error I get:

Fatal error: Cannot redeclare gettext() in /home/a4428795/public_html/demos/gertpage.php on line 11

Link to comment
Share on other sites

ok now I get this error with this code:

 

 

Fatal error: Call to undefined function getpage() in /home/a4428795/public_html/demos/gertpage.php on line 8

 

 

<?php

			        function getSitetext () {
            $url = "www.tizag.com";
            $data = getPage($url);
            preg_match('#<td class="mainIn"><h1>Welcome to Tizag Tutorials</h1>
<p>([a-z0-9,]+)</p><br>	</td>#si', $data, $p);
       	   }
	?>
	This will get the main text from the site Tizag.com<br>
	<br>
	<?php echo getsitetext(); ?>

Link to comment
Share on other sites

well something is undefined but im not sure what?

 

i have $data = getpage($url)

I tried $data = $url->getpage($url)

 

and got this error:

Fatal error: Call to a member function getPage() on a non-object in /home/a4428795/public_html/demos/gertpage.php on line 8

Link to comment
Share on other sites

Call to undefined function getpage()

 

You said something is undefined, but you aren't sure what.  Well the error message tells you what is undefined.  It's telling that you are trying to call a function called "getpage()" but php can't find it.  It doesn't exist. It's undefined.  No offense, but it's not some deep rocket science mystery of the universe thing.. So, now that you know that php can't find a function called getpage(), what do you think your next step should be?  If you couldn't find something, what would you do?

 

Link to comment
Share on other sites

ok I altered the code but now I get this error that is almost the same  :wtf:

 

 <center>
<h1> Get Text From Page </h1>

<?php

			        function getSitetext () {
            $url = "www.tizag.com";
            $data = $url->getPage($url);
            preg_match('#<td class="mainIn"><h1>Welcome to Tizag Tutorials</h1>
<p>([a-z0-9,]+)</p><br>	</td>#si', $data, $p);
		return $value;
       	   }
	   
	   $results = $data->getSitetext();
	?>
	This will get the main text from the site Tizag.com<br>
	<br>
	<?php echo $results ?>
	</center>

 

Error:

 

Fatal error: Call to a member function getSitetext() on a non-object in /home/a4428795/public_html/demos/gertpage.php on line 14

Link to comment
Share on other sites

dude... I don't even know where that object you are trying to use is coming from, but your first error explained everything. If you have a function, that you know for a fact is defined, and you are getting an undefined function error, then what could the most likely solution? maybe your using the wrong function name. Just forget about whatever object nonsense your trying to do make sure you are calling the function you defined.

Link to comment
Share on other sites

Here's a hint, with all the subtlety of a sledgehammer to the forehead:

 

PHP isn't telepathic.  Just because you think there should be a function called getPage() in PHP doesn't mean one actually exists.  In fact, checking the manual (http://www.php.net/quickref.php ...you did know that there exists an online manual, right?) verifies that there's no built-in getPage() function in the language.

 

What does that mean?

 

It means that you'll need to create the getPage() function yourself.  And that means doing more than merely trying to tweak the syntax used to invoke the function.

 

Start there.

Link to comment
Share on other sites

Hi Jnerocorp,

Everyone is try to help you workout the problem for yourself, as this will help you more than just giving the answer,

 

Now you know its not a variables and know its a problem with the functions, so are you calling the correct/existing one or not ? or in this case are we being insensitive ?

 

I really hope that helps

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.