My subject is
some html codes<h3 class="r">Some Title</h3>some html codes
My current pattern is:
"/<h3 class="r"><a href="\/url?\?q\=http(...)/"
The result is:
<h3 class="r"><a href="/url?q=http://
I wanted to get the exact url, http://www.somedomain.com/args/
or just <h3 class="r">Some Title</h3> so i can parse it to return the url.
but i could not make it.
Any help would be appreciated. Thank you!
LIVE DEMO
Try this:
'/<h3 class="r"><a href="\/url?\?q\=(http.*)\/"/'
$string = 'some html codes<h3 class="r">Some Title</h3>some html codes'
preg_match_all('!http://(.*)"!', $string, $result_array);
print_r($result_array);
Try it.
Related
i'm trying to extract "XXXXXXX" with PHP Simple HTML DOM description
<h2 class="title">XXXXXXX</h2>
I tried
$ret = $html->find('h2[class="title"]') ;
but i don't know the next instruction because there is no attribute. How i can do this ?
I need to extract also "XX" from this code, i think it's the same problem no ?
<a id="likeScore" appName='videos' object="video" objectid="96" direction="up" class="button like icon-heart youLike not-active">XX</a>
Thank you !
For the first one I think this could work:
$text = $html->find('h2[class="title"] a',0)->innertext;
For tags with ID you can use something more direct:
$text1 = $html->getElementById("likeScore")->innertext;
or using the #selector syntax
$text1 = $html->find('#likeScore',0)->innertext;
Documentation:
https://simplehtmldom.sourceforge.io/manual.htm#section_access
I have the following HTML:
<div class="video cover" data-thumb="https://i.vimeocdn.com/video/1234567.webp?mw=700&mh=393" style="background-image: url(https://i.vimeocdn.com/video/525930392.webp?mw=700&mh=393);">
I would like to retrieve the data-thumb URL value.
I have attempted to retrieve the value using the following:
$iframe = '<div class="video cover" data-thumb="https://i.vimeocdn.com/video/1234567.webp?mw=700&mh=393" style="background-image: url(https://i.vimeocdn.com/video/525930392.webp?mw=700&mh=393);">';
preg_match('/data-thumb="(.*?)"/', $iframe, $matches);
echo $matches[0];
However, this is not retrieving any matches.
EDIT: Thank you for your help and answers. It appears I made an error with the output of $iframe, which was displaying content from an iframe (doh). So preg_match couldn't target it.
preg_match('/data-thumb="([^"]*)"/', $iframe, $matches);
if (isset($matches[1]))
echo $matches[1]; // echo the value of the data-thumb attribute
This works for me. And indeed, original code works fine too.
Try this regex:
/data-thumb="[\s\S]*?"/
Given the following html code I want to detect the real href of the link. You see that I have a "fake" href in the div too.
$html = '
<a class="test">simple text</a>
<div data-href="yahoo.com">yahoo in div</div>
<a class="blabla" href="google.com">google</a>';
preg_match("'<a.*?href=[\'\"](.*?)[\'\"]'si", $html, $output);
What I got now is yahoo.com but this is not what I need.. I want to receive google.com.
Do you have any ideeas ?
You can try this:
(?<=href=")(\w+)\.\w+(?=">\1[^ ])
Check: https://regex101.com/r/nB1wP4/5
I would try simplify. Try it https://regex101.com/r/oU6kR8/1
\shref="([a-z.\/:]+)"
I have a lot of difficulties in this REGEX stuff, can any one help improve my code?
Thank you in advanced.
What I need is to get the content in side the [Slide] CONTENT [/Slide] tags.
What i am doing is:
preg_match ('/\[Slide\].*\[\/Slide\]/s', $content, $matches);
$conteudo_slide = $matches[0];
$conteudo_full = preg_replace('/\[Slide\]/s', "", $conteudo_slide);
$conteudo_full = preg_replace('/\[\/Slide\]/s', "", $conteudo_full);
the content of the page is:
<p>[Slide]http://www.gprco-cpa.com/images/industries/corporations.jpg[/Slide]</p>
<p>[Slide]http://www.expatcpa.com/Corporation_HQ.jpg[/Slide]</p>
<p><br />[Slide]</p>
<p><a href="http://localhost/~tiago/main_wordpress/?attachment_id=437" rel="attachment wp-att-437">
<img class="alignright size-full wp-image-437" title="lightbulb"src="http://localhost/~tiago/main_wordpress/wpcontent/uploads/2012/09/lightbulb1.jpg" alt="" width="500" height="334" /></a>[/Slide]</p><p> </p>
<p>[Slide]http://www.youtube.com/watch?v=SHVOyGVQ3Tw&feature=g-all-u[/Slide]</p>
IsnĀ“t any more correct way of doing this?
Thank you.
try adding ():
preg_match ('/\[Slide\](.*?)\[\/Slide\]/s', $content, $matches);
I have the following html content:
<p>My name is way2project</p>
Now I want this text as <p>My name is way2project</p>
Is there any way to do this? Please help me thanks
I used preg_replace but in vain.
Thanks again
You can use the strip tags function
$string = '<p>My name is way2project</p>';
echo strip_tags($string,'<p>');
note the second parameter is the list of allowed tags you wont to ignore.
This seems strange, but not knowing the complete scope of your issue and seeing that you want to do this in PHP, you can try:
$origstring = '<p>My name is way2project</p>';
$newstring = str_replace('way2project', 'way2project', $origstring);
echo $newstring;
Checkout Simple Html Dom Parser
$html = str_get_html('<html><body>Hello!SO</body></html>');
echo $html->find('a',0)->innertext; //prints "SO"
strip_tags you can use this, to remove html tags.