The jQuery -
$.ajax({
type: "GET",
url: "add_showcase.php",
data: "title=" + document.getElementById("title_in").value + "&desc=" + document.getElementById("desc_in").value,
success: function(html)....
When i pass this data as "desc" -
<object width="480" height="385">
<param name="movie" value="http://www.youtube.com/v/7M-jsjLB20Y?fs=1&hl=en_US"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/7M-jsjLB20Y?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
</object>
add_showcase.php only receives a part of this data -
desc=<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/7M-jsjLB20Y?fs=1
What would you do if you were to rectify this problem?
Replace the & with the hex value %26 so it looks like http://www.youtube.com/v/7M-jsjLB20Y?fs=1%26hl=en_US
To do this, use Javascript's escape() function. If you need to, use Javascript's unescape() function to convert the hex values back to their original values.
Use POST instead of GET if you have huge data
use
escape(document.getElementById("desc_in").value)
Related
I have here an embed code from youtube and Im using a plugin to show that video
<object width="350" height="200">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="350" height="200">
</embed>
</object>
My problem is I cannot edit those codes, I need to change the "&" sign to "&" for w3c validation, is this possible using jquery
here is My sample fiddle which is not working and dont know how http://jsfiddle.net/kfX9M/
Changing it with jQuery won't make your HTML valid. You could change it server-side with some PHP:
$dom = new DOMDocument();
$dom->loadHTML($your_embed_code_here);
$xpath = new DOMXPath($dom);
$items = $xpath->query("//*[contains(#href,'&')]");
$l = $item->length;
for($i=0; $i<$l; $i++) {
$items->item($i)->setAttribute("href",str_replace("&","&",$items->item($i)->getAttribute("href")));
}
$out = $dom->saveHTML();
But, as mentioned by elclanrs, it really makes no difference.
Hi dude i did with jQuery and Regular Expressions.,
<script type="text/javascript">
$(document).ready( function() {
var re=/&/g;
var value=$("param[name='movie']").val();
var modified_value=value.replace(re,'&');
$("param[name='movie']").val(modified_value);
var src = $("embed").attr('src');
var src_modified_value=src.replace(re,'&');
$("embed").attr('src',src_modified_value);
});
</script>
i think this may help you to resolve your problem.
To see it in action : http://jsfiddle.net/john_rock/7H2Hk/
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 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.
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;