Fluoresce Posted August 27, 2014 Share Posted August 27, 2014 I embed videos on my site. I submit the embed codes to my database using a form. The codes look like this: <iframe width="560" height="315" src="//www.youtube.com/embed/xDIgbjDGsOM?rel=0" frameborder="0" allowfullscreen></iframe> Before I submit each code, I have to change its width and height, and I have to add this: &showinfo=0 after this: ?rel=0 Is there a function that will allow me to do all of that simultaneously? I know about str_ireplace(). It will let me replace ?rel=0 with ?rel=0&showinfo=0, but I don't know how to simultaneously make the other changes. It's not helping that the embed code includes quotation marks. Link to comment https://forums.phpfreaks.com/topic/290691-how-can-i-replace-3-specific-sections-of-a-string-that-includes-quotation-marks/ Share on other sites More sharing options...
Psycho Posted August 27, 2014 Share Posted August 27, 2014 You are storing the entire HTML code to your database? Why not just store the variable parameters separately and build the URLs dynamically. That makes it much more flexible. For example, you might just store three values: height, width and code. Then when you need to output the HTML you would build the entire iframe using those three values. Link to comment https://forums.phpfreaks.com/topic/290691-how-can-i-replace-3-specific-sections-of-a-string-that-includes-quotation-marks/#findComment-1489103 Share on other sites More sharing options...
Fluoresce Posted August 27, 2014 Author Share Posted August 27, 2014 You are storing the entire HTML code to your database? Why not just store the variable parameters separately and build the URLs dynamically. That makes it much more flexible. For example, you might just store three values: height, width and code. Then when you need to output the HTML you would build the entire iframe using those three values. Dude, why didn't I think of that! Thank you! Link to comment https://forums.phpfreaks.com/topic/290691-how-can-i-replace-3-specific-sections-of-a-string-that-includes-quotation-marks/#findComment-1489107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.