Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-19-2012, 11:05 AM Get text from url
Nightmaster's Avatar
Average Talker

Posts: 29
Name: Nikola
Location: Serbia
Trades: 0
Hello all,

I need a help about which method should i use in order to get only text from some specific url and display it (without images, urls, etc). So i just need a plain text, no html or smth.

Thanks!
Nightmaster is offline
Reply With Quote
View Public Profile Visit Nightmaster's homepage!
 
 
Register now for full access!
Old 07-19-2012, 11:25 AM Re: Get text from url
Extreme Talker

Posts: 247
Trades: 3
cURL and strip_tags might get you started.

http://us.php.net/manual/en/book.curl.php
http://php.net/manual/en/function.strip-tags.php
__________________

Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 07-20-2012, 08:36 PM Re: Get text from url
King Spam Talker

Posts: 1,092
Name: Paul W
Trades: 0
But don't do it to steal content, of course.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 07-31-2012, 07:29 PM Re: Get text from url
Average Talker

Posts: 19
Trades: 0
Why don't you use POST?
yoda69 is offline
Reply With Quote
View Public Profile
 
Old 08-02-2012, 04:35 PM Re: Get text from url
Physicsguy's Avatar
404 - Title not found

Posts: 1,061
Name: Scott Kaye
Location: Ontario
Trades: 0
Quote:
Originally Posted by yoda69 View Post
Why don't you use POST?
That makes absolutely no sense. POST is used to send data to a server, not retrieve it

To OP: You could try using file_get_contents() in conjunction with strip_tags(). It's a bit easier than cURL, but not as... what's the word... easy to create/modify?

To get just the content within two divs, there are tons of ways to do that.
__________________

Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 08-18-2012, 02:08 PM Re: Get text from url
Nightmaster's Avatar
Average Talker

Posts: 29
Name: Nikola
Location: Serbia
Trades: 0
Thanks for your anwers. I tried file_get_contents() and it works fine i guess.
Now, all this is because i want to display current Euro exchange rate from the site of our National Bank (It's allowed). I actually just need a data from <div id="blah"> to be displayed on my page, so i wonder if there's some example of script which can do that? I guess that i must use some kind of search within content i get from url?

Thanks!
Nightmaster is offline
Reply With Quote
View Public Profile Visit Nightmaster's homepage!
 
Old 08-18-2012, 03:55 PM Re: Get text from url
Physicsguy's Avatar
404 - Title not found

Posts: 1,061
Name: Scott Kaye
Location: Ontario
Trades: 0
Quote:
Originally Posted by Nightmaster View Post
Thanks for your anwers. I tried file_get_contents() and it works fine i guess.
Now, all this is because i want to display current Euro exchange rate from the site of our National Bank (It's allowed). I actually just need a data from <div id="blah"> to be displayed on my page, so i wonder if there's some example of script which can do that? I guess that i must use some kind of search within content i get from url?

Thanks!
I knew that you'd ask that question which is why I included the third and final link in my previous post. Try this, I've used this method and it's extremely easy to understand, because there aren't any complicated regular expressions.

I'll edit this post when I have some hard code you can copy in (that uses preg_match regexs, not the above method) Be back in a jiffy.

EDIT: Here's some hastily hacked together code that seems to work fine for me.

PHP Code:
<?php

$full_contents 
"Hello there, <div id=\"blah\">useful content</div> nope!";

$tagname 'blah';

$matches=0;
preg_match('/<div\s*id="'.$tagname.'">(.+?)<\/div>/i',$full_contents,$matches);

echo 
$matches[1];  //Should only return 'useful content', because that's what's inside <div id="blah"> ... </div>

?>
And to integrate it with file_get_contents(), just replace the $full_contents variable with your file_get_contents() line. To change the div you're looking for, edit the $tagname variable.
__________________

Please login or register to view this content. Registration is FREE

Last edited by Physicsguy; 08-18-2012 at 04:04 PM..
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Reply     « Reply to Get text from url
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20859 seconds with 11 queries