Use file_get_contents() to read from a specific div? [duplicate] - php

This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
DOMDocument for parsing HTML (instead of regex)
(2 answers)
Closed 9 years ago.
I want to get the text from a div in this page:
<html>
<head>Hello world!</head>
<body>
This is a test!<br>Hello man!<br>
<div class="special">
I want this text
</div>
</body>
</html>
I am using this code to get the content without any tags:
echo strip_tags(file_get_contents('http://website.com'));
However, I would like only to get the content from the
<div class="special">
from that page. Is that possible in PHP?

Use a HTML parser to parse the object you read using file_get_contents(). This question lists a bunch of parsers you could use

Related

How to display HTML DOM elements which is sorted in TPL variable [duplicate]

This question already has answers here:
How to turn off html escape in Smarty
(2 answers)
Closed 2 years ago.
Good morning,
I have variable with HTML code. For example:
{assign var="url" value="<a href='google.com'>URL</a>" nocache}
The next step is display the content.
{$url}
The result is:
<a href='google.com'>URL</a>
How to display the URL which will be a working link?
Kind regards
The answer is to add nofilter parameters to variable:
{$url nofilter}

Split XML Element Variable [duplicate]

This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 7 years ago.
I am integrating with an API which returns data in XML format. I receive a response from the API and store it in a variable named $result. How do I access the clientdetails values from the example response below?
<client_get>
<header>
<messagetype>Response</messagetype>
<submissionnumber>563jd94a2jfoi4f</submissionnumber>
</header>
<clientdetails>
<clientid>23373920</clientid>
<companyname>Testing Test</companyname>
<accountreference>1133</accountreference>
<status>LIVE</status>
</clientdetails>
<gocardlessdetails>
<newsignupurl>https://www.url here>
</gocardlessdetails>
</client_get>
If you can call an external process, there are command line splitters out there. One, xmlsplit, has an option to automatically include that header element in each of the split files, but it is commercial. There are also OS XML splitters.

Code PHP passed to HTML through append doesn't work [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
I am trying pass this code for html but not work, load as text.
HTML:
<div id="captcha-wrap">
<p>
</p>
<!-- show the captcha result - fail/pass -->
<div id="captcha-status">
</div>
JS:
$("#captcha-wrap").append("<?php require_once('_control/showcaptcha.php'); ?>");
You can't append PHP like that. Have a look at using AJAX.

Regex find every instance of element in html [duplicate]

This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Using DOMDocument to extract from HTML document by class
(3 answers)
Closed 9 years ago.
I'm scraping an html page that has X amount of instances of the element class="page-title" inside a div element id="row-1"
So we have something like:
<div id="row-1">
<div class="page-title">
<span><h4><a>text I want to grab</a></h4></span>
</div>
</div>
There could be 1,2,3,10 of these rows. Could anyone help explain how I can grab every instance of the page title if there are multiple rows?
Whatever you do, don't use a regex! HE COMES
Instead, use a parser:
$dom = new DOMDocument();
$dom->loadHTML($your_html_source_here);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//*[#id='row-1']/div[#class='page-title']");

jQuery id selector not working when have . in ID [duplicate]

This question already has answers here:
How to select html nodes by ID with jquery when the id contains a dot?
(8 answers)
Closed 9 years ago.
My html code is as below.
<div id="chatbox_dipesh.parmar" class="chatbox">
//html markup which is validated
</div>
in above code dipesh.parmar div added dynamically.
And i am accessing it using following code.
$("#chatbox_"+chatboxtitle).show();
where chatboxtitle is dipesh.parmar but its not selecting div.
Does . is not a valid for ID.?
My jQuery is loaded and its not conflicting with other library and also wrapped it into $(function(){ }).
Thanks.
Escape the dot.
See this:
Direction

Categories