Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to change youtube short url into embeddable value via form submission to database?
    text
    copied!<p>i'd like to be able to enter a youtube video's short url into a form input eg;</p> <p>'http://youtu.be/rAndoMText'</p> <p>and upon 'submit' perform three functions in the php file that is processing the form: </p> <p>replace:</p> <p><code>'http://youtu.be/'</code> </p> <p>with:</p> <p><code>'&lt;a class='youtube' href="http://www.youtube.com/embed/'</code></p> <p>and add:</p> <p><code>'?rel=0&amp;amp;wmode=transparent"&gt;link&lt;/a&gt;'</code> </p> <p>to the end of the new value</p> <p>and then submit the final value to the database. </p> <p>my current php file is below and it's 'logic' is based on my basic knowledge of php and searching for solutions on the internet and i don't expect it to be correct. </p> <p>it does check out in online syntax checkers though and is sending the other form inputs to the database, just not the one i am trying to modify. </p> <pre><code>&lt;?php $original_link = $_POST["link"]; $prepender = "&lt;a class='youtube' href=\"http://www.youtube.com/embed/\""; $appender = "?rel=0&amp;amp;wmode=transparent\"&gt;link&lt;/a&gt;"; $modified_link = str_replace ("http://youtu.be/","$prepender","$original_link"); $modified_link . "" . $appender = $final_value; $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql="INSERT INTO data (fieldone, fieldtwo, fieldthree, fieldfour, link) VALUES ('$_POST[fieldone]','$_POST[fieldtwo]','$_POST[fieldthree]','$_POST[fieldfour]', '$final_value')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header ('Location: http://return-to-your-website.com'); mysql_close($con); ?&gt; </code></pre> <p>i also tried using this in the 'modified_link' area above but it returned the same results:</p> <pre><code>$modified_link = ""; ob_start (); { echo str_replace ("http://youtu.be/","$prepender","$original_link"); $modified_link = "ob_get_contents ()"; } ob_end_clean (); $modified_link . "" . $appender = $final_value; </code></pre> <p>thank you. </p>
 

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