11

Find a string between custom tags and do something with it

 2 years ago
source link: https://www.codesd.com/item/find-a-string-between-custom-tags-and-do-something-with-it.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Find a string between custom tags and do something with it

advertisements

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK