After more than 3 hours searching in google, I found that ppl do the other way around of what I am doing but anyway, here is what I want to do:
I have a variable $location which contains an HTML code (embedded google map code) i.e.
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://www.google.com/maps/ms?........in a larger
map></iframe>
now in a php code, how can i get the map to be displayed?
the following outputs the HTML code as text
<?php echo $loation; ?>
Thanks!
You spelled your variable name wrong $loation; - should be $location;. Assuming you set your variable correctly like
$location = '...';
OR using heredoc syntax:
$location = <<<STR
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://www.google.com/maps/ms?........in a larger
map></iframe>
STR;
you should be fine.
Related
I want to open the maps in new tap when user click on "view larger map"
'gmap'=>array(
array(
'(https*:\/\/maps.google.co.in\/?[^< ]+)',
'<iframe width="'.qa_opt('embed_gmap_width').'" height="'.qa_opt('embed_gmap_height').'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$1&ie=UTF8&output=embed"></iframe><br /><small>View Larger Map</small>','gmap'
)
),
);
where should I put target="_blank
You should put target="_blank" inside <a> tag. Reference
View Larger Map
Preferably in the <a> tag:
'<iframe width="'.qa_opt('embed_gmap_width').'" height="'.qa_opt('embed_gmap_height').'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$1&ie=UTF8&output=embed"></iframe><br /><small>View Larger Map</small>',
I want to get all YouTube iframe using regex and want to add specific tag to each record found.
For example <youtube-frame></youtube-frame> to iframe begeing and end.
Needed output:
<youtube-frame><iframe width="560" height="315" src="https://www.youtube.com/embed/vakfMRyjulw" frameborder="0" allowfullscreen></iframe></youtube-frame>
<youtube-frame><iframe width="560" height="315" src="https://www.youtube.com/embed/aDGWMlKPKDs" frameborder="0" allowfullscreen></iframe></youtube-frame>
My Code
$embed = '
<iframe width="560" height="315" src="https://www.youtube.com/embed/vakfMRyjulw" frameborder="0" allowfullscreen></iframe>
<iframe width="600" height="350" src="https://tune.pk/player/embed_player.php?vid=6508414&folderp2016/05/04/&width=600&height=350&autoplay=no" frameborder="0" allowfullscreen scrolling="no"></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/aDGWMlKPKDs" frameborder="0" allowfullscreen></iframe>
<iframe width="600" height="350" src="https://tune.pk/player/embed_player.php?vid=6508414&folder=2016/05/04/&width=600&height=350&autoplay=no" frameborder="0" allowfullscreen scrolling="no"></iframe>
<iframe width="600" height="350" src="https://tune.pk/player/embed_player.php?vid=6508414&folder=2016/05/04/&width=600&height=350&autoplay=no" frameborder="0" allowfullscreen scrolling="no"></iframe>
';
What I have tried?
$pattern = '/<iframe\.*src=\"//youtube"\.*/';
$iframeSrc = preg_match($pattern, $embed, $matches);
var_dump($iframeSrc);
Try this:
$iframeSrc = preg_replace('/<iframe[^>]*src\s*=\s*"?https?:\/\/[^\s"\/]*youtube.com(?:\/[^\s"]*)?"?[^>]*>.*?<\/iframe>/i', '<youtube-frame>$0</youtube-frame>', $embed);
This uses preg_replace and a global regex to replace all YouTube IFrame tags (including their closing tags) with <youtube-frame>$0</youtube-frame> where $0 is the original string.
The regex could theoretically be simplified if you are totally sure about the format of your input, but I designed it to be robust enough to cope with other syntaxes such as src=http://example.com or src = "http://example.com" etc. which are accepted by browsers nowadays, and it only matches sources on *.youtube.com domains and not something like myyoutubesite.com.
Hello so I have this code here <iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="http://example.com/signup.php" width="1000"></iframe> now I was wondering is there any way to make a php script that can choose a random iframe code and display the php script on the page for example
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="website1.com/signup.php" width="1000"></iframe>
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="website2.com/signup.php" width="1000"></iframe>
like in website 1 and 2 but have it so each time a person loads that page it switches from site 1 to site 2 and embeds the php or is that n
You could simplify this easily. Try adding the sites to an array like this:
$sites = array(
'site1.com',
'site2.com',
'site3.com',
'site4.com',
'site5.com',
'site6.com',
'site7.com'
);
Now you can use features like array_rand() to pick a random entry from the site to show in your <iframe>:
<?php
$site_to_use = array_rand($sites);
?>
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="<?php echo $sites[$site_to_use]; ?>/signup.php" width="1000"></iframe>
Or you could even use rand() like this:
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="<?php echo $sites[rand(0, (count($sites - 1)))]; ?>/signup.php" width="1000"></iframe>
That avoids the hassles of large if else or switch casestatements.
Example
For example, I have this string containing some number of iframe tags (but there can be also some text or links, so the point is to select only iframe tags):
<p><iframe frameborder="0" height="180" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaphchapeau-rouge-2022014%2F&embed_type=widget_standard&embed_uuid=9ff7c333-5c68-40d6-b9c7-b475c6a8d297&hide_tracklist=1&replace=0&hide_cover=1" width="600" ></iframe></p>
<p><iframe frameborder="0" height="180" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fx-tract-podcast-night-30-skaph%2F&embed_type=widget_standard&embed_uuid=7186f43a-4bc7-431d-8041-f51366355c44&hide_tracklist=1&replace=0&hide_cover=1" width="600" ></iframe></p>
<p><iframe frameborder="0" height="180" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaphclick-clack-07122013-experiment-liberec%2F&embed_type=widget_standard&embed_uuid=7f2202e6-fd70-45ac-ac1e-6c9dca0ad725&hide_tracklist=1&replace=0&hide_cover=1" width="600" ></iframe></p>
<p><iframe frameborder="0" height="180" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2FTFSpodcast%2Ftechno-for-soul-podcast-11-mixed-by-skaph%2F&embed_type=widget_standard&embed_uuid=e3f68ffd-488d-4d78-b369-a46c785f59a5&hide_tracklist=1&replace=0&hide_cover=1" width="600" ></iframe></p>
<p><iframe frameborder="0" height="180" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaphtechno-je-v%C5%A1echno-5%2F&embed_type=widget_standard&embed_uuid=2c80035e-27e8-4321-b07d-395e6777b98c&hide_tracklist=1&replace=0&hide_cover=1" width="600" ></iframe></p>
<p><iframe frameborder="0" height="132" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaphtechno-je-v%25C5%25A1echno-vol-2-liberec-experiment-18052013%2F&embed_uuid=f81d24a4-c2f8-4bc5-a10f-7f3fb2243392&stylecolor=&embed_type=widget_standard" width="480"></iframe></p>
<p><iframe frameborder="0" height="132" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaphexperiment-18012013%2F&embed_uuid=e63685e9-901c-4d71-a1c5-69d0afb130d6&stylecolor=&embed_type=widget_standard" width="480"></iframe></p>
<p><iframe frameborder="0" height="132" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaph-renaissance-winter-mix-2012%2F&embed_uuid=5a7e4685-cf6a-4f84-ba1c-13251d5b7f59&stylecolor=&embed_type=widget_standard" width="480"></iframe></p>
<p><iframe frameborder="0" height="132" src="http://www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fskaph%2Fskaph-mini-technik%2F&embed_uuid=7818bedc-94d0-46b1-8193-4cafcf65ffb5&stylecolor=&embed_type=widget_standard" width="480"></iframe></p>
I need to select random iframe tag string from this and I need both opening and closing tag to be included. I suppose I should use something like explode and then use array_rand() function, but there is no divider. Other option that came to my mind is regex, but understanding of that still escapes me.
Regular expressions are not suitable for parsing HTML. Use a DOM parser instead -- here's a solution using PHP's native DOMDocument class:
$dom = new DOMDocument;
$dom->loadHTML($html);
$iframes = $dom->getElementsByTagName('iframe');
$index = mt_rand(0, $iframes->length);
$random_tag = $iframes->item($index);
In the above code, first a random index between 0 and the total number of tags ($iframes->length) is chosen with mt_rand(), and then the item() method is used to specifically access that tag. Once you have the tag, you can do any further processing. In the demo, I've shown you how to extract the src attribute just to show it's random.
Online demo
Hello everybody and thanks for reading.
I have a link like this :
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?f=q&source=s_q&hl=en&geocode=&q=monte+rosa&aq=&sll=45.454082,9.213138&sspn=0.009016,0.01929&t=h&gl=it&ie=UTF8&hq=&hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&ll=45.690627,8.824349&spn=0.008978,0.01929&z=14&iwloc=A&output=embed"></iframe><br /><small>View Larger Map</small>
i want to extract only this
https://maps.google.it/maps?f=q&source=s_q&hl=en&geocode=&q=monte+rosa&aq=&sll=45.454082,9.213138&sspn=0.009016,0.01929&t=h&gl=it&ie=UTF8&hq=&hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&ll=45.690627,8.824349&spn=0.008978,0.01929&z=14&iwloc=A&output=embed
In other words i want to extract everything after the src=" until the end of the link ".
I have been trying with the use of regex but i cant figure out the correct syntax. Some help would be most appreciated.
$html = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?f=q&source=s_q&hl=en&geocode=&q=monte+rosa&aq=&sll=45.454082,9.213138&sspn=0.009016,0.01929&t=h&gl=it&ie=UTF8&hq=&hnear=Monte+Rosa,+Province+of+Varese,+Lombardy&ll=45.690627,8.824349&spn=0.008978,0.01929&z=14&iwloc=A&output=embed"></iframe><br /><small>View Larger Map</small>';
preg_match('~iframe.*src="([^"]*)"~', $html, $result);
var_dump($result[1]);