I have a script that gets embed code for me.I am using php simple html dom parser.The code i am using is like this :
foreach ($html->find('object embed') as $embedCode)
{
echo $embedCode;
}
and the out put is :
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent">
but it's showing in my browser as a flash screen.I want to print it as a single string.
Can anyone tell me how can i get it as a single string not the video screen.
Thanks in advance
The return of GetMovie() :
<embed wmode="transparent" type="application/x-shockwave- flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="http://server0.stream2k.com/playerjw/player- licensed56.swf"
width="100%" height="320" allowscriptaccess="always" allowfullscreen="true" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=f3513b19d1149102e116" />
use htmlspecialchars:
foreach ($html->find('object embed') as $embedCode)
{
echo htmlspecialchars($embedCode);
}
Try to put output string in htmlspecialchars: echo htmlspecialchars($embedCode);
You can try something like this :
<pre>
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent">
</pre>
Try add this before your "for" loop:
echo '<xmp>';
this will echo all charactors but not display as html code.
Related
For some reason I'm trying to do:
<OBJECT id="affMV737" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">
<param name="movie" value="http://www.domain.com/view.php?banner_id=1">
<param name="allowScriptAccess" value="always">
<embed src="http://www.domain.com/view.php?banner_id=1" width="468" height="60" allowScriptAccess="always" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
</object>
I'm printing the FULL URL in the php but the flash is not loading...
but If i change the src in the flash code to the printed result in the php, the banner is working.
any advice?
thanks.
Not clear what you want but I guess this will help
instead of this:
http://www.domain.com/view.php?banner_id=1
try like this:
<?php echo file_get_contents('http://www.domain.com/view.php?banner_id=1');?>
update:
Another guess.. You need change your view.php to something like this:
header('Content-type: application/x-shockwave-flash');
echo file_get_contents('http://domain.com/files/bnrs/blabla.swf');
I'm just wondering how, and which audio player I should use to allow my visitors to play audio files on my PHP-based website.
Thanks!
try this
<?php
$path = "PATH OF YOUR AUDIO FILE";
$image = "PATH OF YOUR IMAGEFILE";;?>
<div class="demomain">
<br>
<div style="margin: 0 0 0 30px;" id="mediaspace" name="mediaspace"><embed height="395" width="500" flashvars="javascriptid=JW&autostart=false&width=500&height=395&image=<?php echo $image; ?>&file=<?php echo $path; ?>" allowfullscreen="true" wmode="transparent" allowscriptaccess="always" quality="high" name="JW" id="JW" style="undefined" src="http://player.longtailvideo.com/player4.6.swf" type="application/x-shockwave-flash"> </div>
<?php
echo '<script type="text/javascript">
var s1 = new SWFObject("","JW","500","395","9");
s1.addParam("allowscriptaccess", "always");
s1.addParam("wmode","transparent");
s1.addParam("allowfullscreen","true");
s1.addVariable("javascriptid", "JW");
s1.addVariable("autostart","false");
s1.addVariable("image","' . $image . '"));
s1.addVariable("width","500");
s1.addVariable("height","395");';
echo 's1.addVariable("file","' . $path . '");';
echo 's1.write("mediaspace");';
echo '</script>';
?>
</div>
HTML 5 has an audio player tag,see this:
http://www.w3schools.com/html5/att_audio_src.asp
it is supported on major browsers, but it depends on the format of the audio file
you can see this: http://jplayer.org/ a jquery one,
The open source jPlayer works well and is very customisable - uses HTML/CSS for the interface. Will use HTML5 if it can, and fallback to Flash if not. Requires jQuery.
Website: http://jplayer.org/
You can try Flash Player. I think it will suite your requirement. Of course you should have the flash player installed, but practically almost all internet users have the flash player installed in their machines.
try this
<object height="81" width="100%">
<param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true">
</param>
<param name="allowscriptaccess" value="always"></param>
<embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true&repeat=1" type="application/x-shockwave-flash" width="100%" loop="yes" autoresume="1" repeat="1">
</embed>
</object>
use this <audio controls><source src="<?php echo $pathtofile ?>" type="audio/mpeg">Error loading</audio> It works for me.
hey guys,
a php variable $htmlholds the following object...
<object width="562" height="200">
<param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3">
<param name="allowFullScreen" value="true">
<param name="allowscriptaccess" value="always">
<embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3"
type="application/x-shockwave-flash"
width="562"
height="200"
allowscriptaccess="always"
allowfullscreen="true">
</object>
any idea how I could filter the width and height both of the object- and embed-tag to have 100% values?
<object width="100%" height="100%">
...
<embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3"
type="application/x-shockwave-flash"
width="100%"
height="100%"
allowscriptaccess="always"
allowfullscreen="true">
</object>`
Thanks for your help!
update:
$chunk = $dom->getElementsByTagName('body')->item(0);
$objectHtml = '';
foreach($chunk->childNodes as $node) {
$objectHtml .= $node->saveXML();
}
return $objectHtml;
says: Call to undefined method DOMElement::saveXML()
whereas...
$dom = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveXML()));
works fine! however I get weird inserted in my sourcecode when using this..
like this:
<!--?xml version="1.0" standalone="yes"?-->
<br>
<br>
<object width="95%" height="75%"><param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3" type="application/x-shockwave-flash" width="95%" height="75%" allowscriptaccess="always" allowfullscreen="true"></object>
any idea what I'm doing wrong here?
It is often better to use a HTML parser instead of a regex when modifying HTML.
$dom = new DOMDocument;
$dom->loadHTML($str);
$object = $dom->getElementsByTagName('object')->item(0);
$object->setAttribute('width', '100%');
$object->setAttribute('height', '100%');
$embed = $object->getElementsByTagName('embed')->item(0);
$embed->setAttribute('width', '100%');
$embed->setAttribute('height', '100%');
echo $dom->saveXML($dom->getElementsByTagName('body')->item(0));
You probably don't want the element wrapped in body, so do this...
$objectHtml = '';
foreach($chunk->childNodes as $node) {
$objectHtml .= $dom->saveXML($node, LIBXML_NOEMPTYTAG);
}
Where $chunk is $dom->getElementsByTagName('body')->item(0).
I added the option LIBXML_NOEMPTYTAG, otherwise if you have <span></span> it will be turned into <span />.
If using >= PHP 5.3, use saveHTML() instead.
Is that all that your string will contain? If so, you can use this:
$replace = preg_replace(
"/(width|height)=\".*?\"/",
"\${1}=\"100%\"",
$html
);
You can tweak the pattern to allow for whitespace between the attribute, = sign, and value as necessary.
If your string will contain more HTML, with their own width/height attributes you don't want replaced, then you'll need a more robust solution.
preg_replace('/(width|height)(=)"([\d]+)"/', '${1}${2}"100%"', $html);
That should do the trick :)
$html = '<object width="562" height="200"><param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3" type="application/x-shockwave-flash" width="562" height="200" allowscriptaccess="always" allowfullscreen="true"></object>';
$pattern = '/(<object[^>]*width=)\".*?(\"[^>]*height=)\".*?(\"[^>]*>.*?<embed[^>]*width=)\".*?(\"[^>]*height=)\".*?(\"[^>]*>.*?<\/object>)/si';
$replace = '\1"100\2"200\3"300\4"400\5';
echo preg_replace($pattern, $replace, $html);
This should work.
Set, 100, 200, 300, 400 to your values.
On my new project, members are able to use my YouTube API and it will generate a tag like below for them to use it in whatever textarea they want:
<ymedia>http://www.youtube-nocookie.com/v/qQG0XfU-bFs</ymedia>
I want my PHP profile page to take the string between <ymedia></ymedia> and generate a similar code below using $ymstring for the string collected from the ymedia tag:
<?php
$u_agent = $_SERVER[''HTTP_USER_AGENT''];
if(preg_match(''/Opera/i'',$u_agent)){
<object width="320" height="240" data="".$ymstring."?fs=1&hl=en_US&rel=0"><param name="movie" value="".$ymstring."?fs=1&hl=en_US&rel=0" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /><param name="bgColor" value="#ffffff" /><param name="flashvars" value="vu=".$ymstring."?fs=1&hl=en_US&rel=0" /></object>
} else {
<object width="320" height="240"><param name="movie" value="".$ymstring."?fs=1&hl=en_US&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="".$ymstring."?fs=1&hl=en_US&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object>
}
?>
Basically, I'm trying to find all the ymedia tags in a $string and replace them with my youtube coding above aimed at either Opera or the rest of other browsers.
This should work:
preg_match("/<ymedia>(.*?)<\/ymedia>/", $Input, $Matches);
Then, your result would be in $Matches[1] which you could pass as $ymstring.
You want to use preg_replace_callback for simplicity:
$html = preg_replace_callback('#<ymedia>(http://.*?)</ymedia>#',
"ymedia_cb", $html);
function ymedia_cb($matches) {
$url = $matches[1];
return "<object src=$url>";
}
Obviously you would use your if/else construct to return the appropriate and complete object tag.
I've some troubles using Preg_replace and preg_match_all to convert a Youtube URL to embed code. Yes, I know that this topic has already touched in stackoverflow but not exactly like I want.
I can get the ID from a url, without html, with that:
http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?
But I've the url formatted with like this:
http://www.youtube.com/watch?v=C9KAqhbIZ7o
And I want to convert it all to this:
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>
Somebody can do some magic and tell me the correct expression to detect all the url, get the ID once and convert all to an embed code? Thank you so much in advance!
Update information:
In order to help and make it a more concise...
I've this:
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! http://www.youtube.com/watch?v=C9KAqhbIZ7o</p>
And I want to get this:
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! <object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
Thanks all for your help, I really appreciate it!
I use this code
// url of video
$url = $row['url'];
$id=0;
// we get the unique video id from the url by matching the pattern
preg_match("/v=([^&]+)/i", $url, $matches);
if(isset($matches[1])) $id = $matches[1];
if(!$id) {
$matches = explode('/', $url);
$id = $matches[count($matches)-1];
}
// this is your template for generating embed codes
$code = '<div id="img_wrapper"><object width="640" height="458"><param name="movie" value="http://www.youtube.com/v/{id}&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/{id}&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>';
// we replace each {id} with the actual ID of the video to get embed code for this particular video
$code = str_replace('{id}', $id, $code);
echo $code;
Replace $html with your html string which needs parsing.
$html=<<<HTML
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! http://www.youtube.com/watch?v=C9KAqhbIZ7o</p>
HTML;
$regex="/v\=([\-\w]+)/";
preg_match_all($regex,$html,$out);
$out[1]=array_unique($out[1]);
foreach($out[1] as $o){
$reg="/(<a).*(youtube.com).*($o).*(\/a>)/";
$embed= <<<HTML
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/$o=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>
HTML;
$html=preg_replace($reg,$embed, $html);
}
echo $html;