I'm trying to get the html5player.setVideoUrlHigh var from an external source that renders like this:
<script>
logged_user = false;
var static_id_cdn = 2;
var html5player = new HTML5Player('html5video', '38295'); //this is the video ID
if (html5player) {
html5player.setVideoTitle('video title goes here');
html5player.setVideoUrlHigh('https://random-prefix-here.site-url.com/videos/mp4/random-part-of-url');
...
}
</script>
Firstly, I do file_get_contents to get the embed code:
$videoID = 38295;
$url = file_get_contents('https://www.site-url.com/embedframe{$videoID}');
then, I look for a url match that contains specific parts like (site-url.com/videos/mp4/) to eco it, like this:
preg_match('/https:\/\/[^\"]*/\.site-url\.com\/videos\/mp4\/[^\"]*/', $url, $matches, PREG_OFFSET_CAPTURE);
$videoURL = ($matches[0][0]);
echo '=>' . $videoURL;
but this is not working... Where am I failing?
Please keep in mind that both random-prefix-here and random-part-of-url should be replaced by regex in a possible solution.
UPDATED
I already tried this also, witouth any results:
$url = 'http://www.site-url.com/embedframe38295/';
$content= file_get_contents($url);
preg_match_all('#html5player.setVideoUrlHigh\((.+?)\')', $url, $matches, PREG_OFFSET_CAPTURE);
$videoURL = ($matches[0][0]);
echo $videoURL;
Related
I'm trying to get the url inside a tag within script html5player.setVideoUrlHigh('http://www.example.com/videourl_here.mp4')
Currently using this script but is not working:
$url = 'http://www.siteurl.com/embedframe38295/';
$content= file_get_contents($url);
preg_match_all('#html5player.setVideoUrlHigh\(\'.*'/')', $url, $matches, PREG_OFFSET_CAPTURE);
$videoURL = ($matches[0][0]);
echo $videoURL;
What can be the problem?
I have a code for embedding a link for iframe.
$post_contetn = explode('htt',$content);
$content_with_link = $post_contetn[0];
$link = 'htt'.$post_contetn[1];
But the problem is that, if I write
http://www.espn.com was great
then it links "was great" is part of the $link.
How can I change (perhaps use regex) to only include the actual url?
======
If I incorporate siam's answer, should it be
$regex = '/https?:\/\/.*?(?=\s)/';
$post_contetn = preg_match($regex, $content, $linkarray);
$content_with_link = $post_contetn[0];
$link = $linkarray[0]
echo $content_with_link;
I then edited to
preg_match($regex, $content, $post_contetn);
$content_with_link = $post_contetn[0];
$link = $post_contetn[0]
echo $content_with_link;
But the error still occurs at echo line.
Try using the following regex :
(?:https?:\/\/\S+)?\S+\.\S+\.?\S+
see demo / explanation
PHP
<?php
$content = 'http://www.espn.com was great';
$regex = '/(?:https?:\/\/\S+)?\S+\.\S+\.?\S+/';
preg_match($regex, $content, $post_contetn);
$link = $post_contetn[0];
echo $link;
?>
i got Source Code From Remote Url Like This
$f = file_get_contents("http://www.example.com/abc/");
$str=htmlspecialchars( $f );
echo $str;
in that code i want to replace/extract any url which is like
href="/m/offers/"
i want to replace that code/link as
href="www.example.com/m/offers/"
for that i used
$newstr=str_replace('href="/m/offers/"','href="www/exmple.com/m/offers/',$str);
echo $newstr;
but this is not replacing anything now i want to know 1st ) can i replace by str_replace ,in the code which is fetched from remote url and if 'yes' how ...? if 'no' any other solution ?
There will not be any " in your $str because htmlspecialchars() would have converted them all to be " before it got to your str_replace.
I start assuming all href attributes belong to tags.
Since we know if all tags are written in the same way. instead of opting for regular expressions, I will use an interpreter to facilitate the extraction process
<?php
use Symfony\Component\DomCrawler\Crawler;
$base = "http://www.example.com"
$url = $base . "/abc/";
$html = file_get_contents($url);
$crawler = new Crawler($html);
$links = array();
$raw_links = array();
$offers = array();
foreach($crawler->filter('a') as $atag) {
$raw_links[] = $raw_link = $atag->attr('href');
$links[] = $link = str_replce($base, '', $raw_link);
if (strpos($link, 'm/offers') !== false) {
$offers[] = $link;
}
}
now you have all the raw links, relative links and offerslinks
I use the DomCrawler component
Here is my regex to get the image url on the page.
<?php
$url = $_POST['url'];
$data = file_get_contents($url);
$logo = get_logo($data);
function get_logo($html)
{
preg_match_all('/\bhttps?:\/\/\S+(?:png|jpg)\b/', $html, $matches);
//echo "mactch : $matches[0][0]";
return $matches[0][0];
}
?>
Is there any thing missing in regex? for some of the url it does not give image url though they have image in it.
for example: http://www.milanart.in/
it does not give image on that page.
Please No dome. I could not use it.
<?php
$url = "http://www.milanart.in";
$data = file_get_contents($url);
$logo = get_logo($data);
function get_logo($html)
{
preg_match_all("/<img src=\"(.*?)\"/", $html, $matches);
return $matches[1][0];
}
echo 'logo path : '.$logo;
echo '<img src="'.$url.'/'.$logo.'" />';
?>
Use DOM Class of PHP to get all images:
Search for image files in CSS.....url(imagefilename.extension)
Search for image file in HTML ......
See i have an url in a html code
play
Now i want to print this url as it is written in a php page
http://b48.ve.vc/b/data/48/3746/05 Dabangg Reloaded_-_www.DjPunjab.Com.mp3
You can see that between the url 05 Dabangg Reloaded their is space. I made this program to print url from this html code..
$str = "play";
$pattern = '`.*?((http|ftp)://[\w#$&+,\/:;=?#.-]+)[^\w#$&+,\/:;=?#.-]*?`i';
if (preg_match_all($pattern,$str,$matches))
foreach($matches[1] as $data)
{
$str=$data;
echo $str;
}
Then i am getting this
http://b48.ve.vc/b/data/48/3746/05
please do not mention on foreach($matches[1] as $data) line bcoz i am using it with so many urls.. I just want to know how to print the whole url in this format.
http://b48.ve.vc/b/data/48/3746/05 Dabangg Reloaded_-_www.DjPunjab.Com.mp3
Spaces are become a huge matter.. Do not know how to fix it..
What i need to add inside
$pattern = '`.*?((http|ftp)://[\w#$&+,\/:;=?#.-]+)[^\w#$&+,\/:;=?#.-]*?`i';
For making it completely workable.
Please suggest me any idea.
$str = 'play';
$arr = explode("\"", $str);
$pattern = '`.*?((http|ftp)://[\w#$&+,\/:;=?#.-]+)[^\w#$&+,\/:;=?#.-]*?`i';
$url = preg_grep($pattern,$arr);
$url = implode('',$url);
Output: $url = 'http://b48.ve.vc/b/data/48/3746/05 Dabangg Reloaded_-_www.DjPunjab.Com.mp3'
Update: 2nd Solution [Reference-DOMElement].
$str = 'play';
$DOM = new DOMDocument;
$DOM->loadHTML($str);
$search_item = $DOM->getElementsByTagName('a');
foreach($search_item as $search_item) {
$url = $search_item->getAttribute('href');
}
echo $url; //Output: http://b48.ve.vc/b/data/48/3746/05 Dabangg Reloaded_-_www.DjPunjab.Com.mp3
You can str_replace each one -space- with %20 for encoding your URL
<?php
$url_org = 'http://b48.ve.vc/b/data/48/3746/05 Dabangg Reloaded_-_www.DjPunjab.Com.mp3';
$url_edited = str_replace(" ", '%20', $url_org);
?>
HERE
This will work.