Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a regular expression to do this for you. If you have ONLY youtube URLs stored in your database, then it would be sufficient to take the part after the last slash 'IkZuQaTIs0' and place it in the src attribute after 'http://www.youtube.com/'. </p> <p>For this simple solution, do something like this:</p> <pre><code>&lt;?php if ($video['VideoType']) { $last_slash_position = strrpos($video['VideoType'], "/"); $youtube_url_code = substr($video['VideoType'], $last_slash_position); echo "&lt;a rel=\"shadowbox;width=700;height=400;player=swf\" href=\"http://www.youtube.com/".$youtube_url_code."\"&gt; View Video&lt;/a&gt;"; } ?&gt; </code></pre> <p>I cannot test it at the moment, maybe you can try to experiment with the position of the last slash occurence etc. You can also have a look at the function definitions:</p> <p><a href="http://www.php.net/manual/en/function.substr.php" rel="nofollow">http://www.php.net/manual/en/function.substr.php</a></p> <p><a href="http://www.php.net/manual/en/function.strrpos.php" rel="nofollow">http://www.php.net/manual/en/function.strrpos.php</a></p> <p>However, be aware of the performance. Build a script which prases your database and converts every URL or stores a short and a long URL in each entry. Because regular expressions in the view are never a good idea. </p> <p>UPDATE: it would be even better to store ONLY the youtube video identifier / url code in the database for every entry, so in the example's case it would be IkZuQ-aTIs0. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload