Jump to content

How can I replace 3 specific sections of a string that includes quotation marks?


Fluoresce
Go to solution Solved by Psycho,

Recommended Posts

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
Share on other sites

  • Solution

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.

  • Like 1
Link to comment
Share on other sites

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! :happy-04:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.