Fixing width of some elements with Regular Expressions

I'm using tinyMCE for a website, and I usually paste Word tourism offers in it, which create certain DIVs with all kind of widths, while my main DIV (which also contains the <textarea> for tinyMCE) is around 550px width.

I would like to use regex in order to reduce width of all possible elements inside my main div to 550px - as someone else but me uses the page editor as well, and he doesn't know how to manually modify width of word-created-element.

-------------Problems Reply------------

With php you could preg_replace dimensions:

preg_match('"@[";\s]width\s*:\s*([0-9]{3,})[email protected]', $html, $matches);

foreach($matches as $match)
// if > 550 then make it 550
if((int)$match[1] > 550)
$new = str_replace((int)$match[1], '550', $match[0]);
$html = str_replace($match[0], $new, $html);

Remember though that...

widths can be in ems or % too padding and border add to dimensions floating things can put them next to each other

... and for those reasons I suggest you are better to add overflow:hidden to your main DIV

Category:php Views:0 Time:2011-08-28
Tags: php html regex css

Related post

  • Substitute Array Elements into Regular Expression Statements / Variable Names 2010-08-24

    Been wondering if this is doable in AWK for some time but always worked around it in the past. Below I initialize an array with 3 months of the year... for readability I ommited the other 9 months. These months are then used in the if-statement as pa

  • How can I match HTML elements with regular expressions? 2011-01-28

    The following codes does not work, I am trying to retrive TR strings from a HTML table. Is there any issue with this code or any other solution available? public static List<string> GetTR(string Tr) { List<string> trContents = new List

  • What are the zero width elements in a regular expression? 2010-11-25

    Recently I am seeing these "zero width elements" in regular expressions. What are they? Can they be treated as ghost data, so that for replacement, they won't be replaced, and for ( ) matching, they won't go into the matches[1], matches[2], etc? Is t

  • Python regular expressions: search and replace weirdness 2010-09-22

    I could really use some help with a Python regular expression problem. You'd expect the result of import re re.sub("s (.*?) s", "no", "this is a string") to be "this is no string", right? But in reality it's "thinotring". The sub function uses the en

  • determine if regular expression only matches fixed-length strings 2010-09-02

    Is there a way of determining if the regular expression only matches fixed-length strings ? My idea would be to scan for *,+ and ? Then, some intelligent logic would be required to to look for {m,n} where m!=n. It is not necessary to take the | opera

  • HTML select element with fixed width and scrollbars 2010-02-17

    This is probably a basic CSS question, but I am not fluent in CSS and just seem to be going in circles. Here's what I have in English: I have a fixed width select element of 400px. The text for each of the options does not fit in that 400px width. I

  • Regular expression for getting text between XML elements 2012-02-23

    I am looking at this regular expressions <(\\w*)>\\.*</(\\w*)> Going thru tutorials etc. I understand it as reading, match anything that follows the form <tag1>blah</tag1> i.e. an XML element, some text and a closing XML eleme

  • Using C# Regular expression to replace XML element content 2009-01-15

    I'm writing some code that handles logging xml data and I would like to be able to replace the content of certain elements (eg passwords) in the document. I'd rather not serialize and parse the document as my code will be handling a variety of schema

  • Regular Expression to Find/Replace in a Fix Length File 2009-04-08

    So I have this big file of fix length lines. I want to do a find and replace on a character line position. Example: xxxxxxx 010109 xxxxxx xxxxx xxxxxxx 010309 xxxxxx xxxxx xxxxxxx 021506 xxxxxx xxxxx xxxxxxx 041187 xxxxxx xxxxx So in this case I woul

  • Replace an XML element's value? Sed regular expression? 2009-08-28

    I want to take an XML file and replace an element's value. For example if my XML file looks like this: <abc> <xyz>original</xyz> </abc> I want to replace the xyz element's original value, whatever it may be, with another strin

  • regular expression to locate form elements - c# 2009-09-16

    I posted this question yesterday: yesterday's question One of the response was to use Reg Expression to locate the form elements. The clients system, returns a HTML page, and the page contains the following hidden elements - <input type="hidden" n

  • How do I write a Regular Expression to match any non-empty content of an XML element that has no children elements? 2009-12-11

    I am trying to match elements that have no other children elements, but also have content. No content also includes whitespace and &nbsp; characters. I need to do this in C#. Take this XML for instance: <1> <2><3 /></2>

  • Chopping a string into a vector of fixed width character elements 2010-02-11

    I have an object containing a text string: x <- "xxyyxyxy" and I want to turn that into a vector with each element containing two letters: [1] "xx" "yy" "xy" "xy" it seems like the strsplit() should be my ticket, but since I have no regular expres

  • SQL Server Express 2005: How to import fixed width data using BCP 2010-03-03

    I’m trying to import fixed width data from text file into SQL Server Express using BCP. I have read some Microsoft’s web pages about this matter, but I haven’t got far with them. Can please give some examples or point to some good tutorials about thi

  • PHP regular expression skip element 2010-08-16

    I have written regular expression which converts text links into clickable link. The code works fine however when an HTML tag is passed it mess the code Here is my code $text = preg_replace('#(?<![">])((http|ftp)s?://[^<>\s]+)#i', '<a

  • Regular expression to match a certain HTML element 2010-10-06

    I'm trying to write a regular expression for matching the following HTML. <span class="hidden_text">Some text here.</span> I'm struggling to write out the condition to match it and have tried the following, but in some cases it selects ev

  • How can I make this regular expression extract contents of certain HTML elements in my document? 2010-10-14

    I've spent a good few hours trying to get this regular expression to work and I'll I've got so far is one big headache! I'm using cURL to load a page into variable $o. Now somewhere in this page is the following: <tr valign="top"> <td>val

  • Regular Expressions to find C++ elements? 2010-11-11

    I'm looking for some predefined Regexes for elements of ANSI C++. I would like to create a program which takes a headerfile (with includes, namespaces, classes etc) as input and returns lists with the found classnames, methods, attributes etc. Its ha

  • How do I set a fix width to an inner div-element when using display properties 2011-01-20

    I'm looking for a property, which a.)centers an inner div-element horizontal b.)sets the width of that inner div-element to a fix width of 40px I tried following to see whether it works. I used display:table and display:table-cell because there will

Copyright (C), All Rights Reserved.

processed in 0.268 (s). 11 q(s)