0

Currently I have many many posts and pages in a WordPress database many of which have iframes on them. The Iframe width and height are different for almost all of them. I want them to be uniform. They currently look like this:

[tab:Just A short code]
<iframe width="560" height="315" src="https://www.youtube.com/embed/aD4grQXZPfg" frameborder="0" allowfullscreen></iframe>
[tab:Another shortcode]
<IFRAME SRC="http://some-other-video-host.com/embed-ksq9vn3gwc16.html" FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO WIDTH=250 HEIGHT=180></IFRAME>

So the iframes are on the pages in different ways such as the width and height being before the src and on some posts/pages it being after the src. Also it may vary in case as you can see on the second iframe width, height etc are in capitals. I want to go through all the posts and change height to 600 and width to 360.

The result output would look like this:

[tab:Just A short code]
<iframe width="600" height="360" src="https://www.youtube.com/embed/aD4grQXZPfg" frameborder="0" allowfullscreen></iframe>
[tab:Another shortcode]
<IFRAME SRC="http://some-other-video-host.com/embed-ksq9vn3gwc16.html" FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO WIDTH=600 HEIGHT=360></IFRAME>

Additional information:

I don't use iframes in the database for anything else so this might simplify the regex that I'm blindly assuming is needed to perform the query.

Any help or suggestions are warmly appreciated.

d.ariel
  • 197
  • 1
  • 11

1 Answers1

1

Use any editor with regex to find these regexes

  • Width: (?<= width=").*?(?=")|(?<= WIDTH=).*?(?=[ >])
  • Height: (?<= height=").*?(?=")|(?<= HEIGHT=).*?(?=[ >])

And replace by the number you want. This will replace all width and height values across your document, not only the ones in iframes. Is that want you wanted?

Nicolas
  • 6,611
  • 3
  • 29
  • 73
  • Thanks Croutonix for the answer. I'd like it to only modify values within the iframes since all the values I need changed are within said iframes, this may cause unexpected results like with images possibly if I'm not careful. Could you integrate that into an sql query or I could dump the database and possibly run awk? If you'd further suggest or recommend a command to do it with I'd be grateful. Some extra information: the server I'm running is ubuntu 14.04 – d.ariel Nov 12 '16 at 14:26
  • MySQL doesn't seem to have a regex replacement feature, you could use any of the solutions [here](http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql). As for matching only in iframes, I'll look into it soon. I can't really help you any further, I don't know a lot about servers and mySQL. – Nicolas Nov 12 '16 at 14:41
  • Thank you for your help thus far Croutonix – d.ariel Nov 12 '16 at 15:12
  • Found a solution in regex for matching only in iframes except you need to be able to reference a group which isn't possible is mySQL. `)).*?>` see [here](https://regex101.com/r/ojaxsR/1). Group 1 matches the value. – Nicolas Nov 12 '16 at 15:19
  • The `(?` thingies are not implemented in MySQL's regexp. – Rick James Nov 15 '16 at 03:55
  • Well I dont think this is possible without lookaheads and lookbehinds... – Nicolas Nov 15 '16 at 12:25