kapz22 Posted November 26, 2011 Share Posted November 26, 2011 Hi All, I am fairly new to PHP. I want to write some code that will get content from specific classes that are in a HTML page. I.e. <p>text 1</p> <p class="description">text2</p> <p>text3</p> I want to just output text where class = description. How would i do this? Quote Link to comment https://forums.phpfreaks.com/topic/251851-get-contents-of-a-url-and-show-only-specific-text/ Share on other sites More sharing options...
Laash Posted November 26, 2011 Share Posted November 26, 2011 Hi You can use jQuery to do that in a much easier way. You will need the jquery library from here: http://docs.jquery.com/Downloading_jQuery#Current_Release And the code: <script type="text/javascript"> $(document).ready(function() { var temp=$(".description").html(); alert("description is"+temp); }); Quote Link to comment https://forums.phpfreaks.com/topic/251851-get-contents-of-a-url-and-show-only-specific-text/#findComment-1291373 Share on other sites More sharing options...
kapz22 Posted November 26, 2011 Author Share Posted November 26, 2011 Sorry, i should have been a bit more specific. E.g. I want to retrieve a URL i.e. http://www.bbc.co.uk/news/...... From that URL, i just want to get the text from the news story. How would i go about it. Quote Link to comment https://forums.phpfreaks.com/topic/251851-get-contents-of-a-url-and-show-only-specific-text/#findComment-1291429 Share on other sites More sharing options...
kicken Posted November 27, 2011 Share Posted November 27, 2011 Use DomDocument to parse the html into a dom tree, then you can traverse it and find what you need. Quote Link to comment https://forums.phpfreaks.com/topic/251851-get-contents-of-a-url-and-show-only-specific-text/#findComment-1291435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.