Topic: need a way to seacrh and move html tags in a string.... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=29174" title="Pages that link to Topic: need a way to seacrh and move html tags in a string.... (Page 1 of 1)" rel="nofollow" >Topic: need a way to seacrh and move html tags in a string.... <span class="small">(Page 1 of 1)</span>\

 
paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 05-01-2007 16:18

Hi guys Im in a fix...

I need to work on a regular expression or a snippet that searches a given string for html opening and closing tags... and what it does is that it moves all closing html tags to the end of the string and all opening tags to the beginning of the string..so for example lets say this string:

code:
stuff one <span style="blablaba">text tex <strong>somesome text </strong>more text more text </span> ending stuff



becomes this:


code:
<span style="blablaba"><strong>stuff one text tex somesome text more text more text ending stuff</strong></span>



ANy one have any ideas or tips please do share...

Thanks again in advance

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana
Insane since: Aug 2000

posted posted 05-01-2007 18:27

What are you trying to do this with? If you're using a language like Perl you would be better off using a loop and a couple of expressions. For example:

code:
$leading = "";
   $trailing = "";
   while ($string =~ s/(<[^>]*>)//)
     {
      my $tag = $1;
      if  ($tag =~ /<\//)     { $trailing .= $tag }
      else                    { $leading .= $tag }
     }

   $string = $leading . $string . $trailing;



.



-- not necessarily stoned... just beautiful.


(Edited by hyperbole on 05-01-2007 18:29)

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 05-01-2007 18:32

well actually I'm tweaking a plugin of tinymce javascript editor. I'm trying to make a plugin that imitates the actions of the format painter option in MS outlook - don't ask why, my boss just HAS TO HAVE THAT integrated.

The darn plugin is supposed to actually when you select a bunch of text - it applies the style of the first element in the selection to all the text selected.

I figured out one simple but very crude idea and that was to move all the closing tags inside the selection to the end of the selection and move all opening tags to the front of teh selection i.e. all strong, italic etc tags would be pushed to either extreme.. The darn thing has had me biting my head off for the whole day and I have absolutely idea how to go from here.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu