65050

how do I store a youtube embed link in a database

When I save a youtube embed iframe into my database it adds a bunch of slashes when i recall it. Like so below.

<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/ycHXRWRKrdA?rel=0\" frameborder=\"0\" allowfullscreen></iframe>

its is being stored in a longtext type. what would remove the slashes when I recall it from the database or prevent slashes being stored in the first place

Answer1:

if you use PHP, you can use stripslashes().

Alternatively you can base64 encode / decode the code.

Answer2:

Don't save the HTML like that - just save the youtube unique ID and then spit out the HTML and plug in the ID from the database.

PHP Regex to get youtube video ID?

Answer3:

once and for all add this in your .htaccess:

# disable the automatic-quote-removing from requests php_value magic_quotes_gpc off

you didnt say if you save the youtube url in a JSON in database. if yes, replace possible quotes via:

str_replace('\"','\\"',$url);

also, of course its better idea to save just the youtube code as:

$eurl = explode("/",$url); $eurl[sizeof($eurl)-1]; // <-- to database

Recommend

  • what is the purpose of setting variables to empty (“ ”) after defining them?
  • How to decode eval(stripslashes(gzinflate
  • Error with PHP Form - Non-functional [closed]
  • Auto email responding
  • PHP: getting “SSA's” instead of “SSA's”
  • Using die() to return ajax value in PHP
  • PHP MySQL query using UNIONs and locating which table the data came from
  • change password in mysql table?
  • Submit external form without leaving the page/site
  • Stripslashes in Android/Java
  • Adding single quote into mysql results with \\'s sometimes but not always
  • Use array in PHP to compare username/password
  • Single property not getting bound on HttpPost
  • Is there a way to query if array field contains a certain value in Doctrine2?
  • Unexpected T_ELSE in php code
  • YouTube URL - regex
  • Arabic data transfer between multiple tables in different MySQL databases returning ???????? as new
  • Both player will playback if set html5 autoplay to be true when using flash to html5 fallback
  • height=100% do not work
  • how do I store a youtube embed link in a database
  • Convert youtube url to iframe embed code
  • Is there a way to apply characters limit inside wp_editor function?
  • How to hide the URL Of Custom Tab?
  • Why does mysqli fetch() return empty results from longtext column?
  • CKEditor and iFrame/YouTube/Other Embed Plugins Show Weird HTML Code
  • How to add regEx in angular filter
  • Embedded Google Maps in Rails not responsive
  • Adjust width of select element according to selected option's width
  • Keep this build forever option - Jenkins
  • Converting a WriteableBitmap image ToArray in UWP
  • Jquery UI tool tip close icon
  • Is there any way to access browser form field suggestions from JavaScript?
  • Hazelcast - OperationTimeoutException
  • Do I've to free mysql result after storing it?
  • A cron job substitute?
  • json Serialization in asp
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?