Current location: Hot Scripts Forums » Programming Languages » PHP » Help with regular expression... :)

Help with regular expression... :)

 
Prev Previous Post   Next Post Next
  #1  
Old 01-08-06, 09:19 PM
eddyvlad eddyvlad is offline
Wannabe Coder
 
Join Date: Sep 2003
Location: In The Bloody Pits Of Hell
Posts: 152
Thanks: 0
Thanked 0 Times in 0 Posts
Help with regular expression... :)

I did a regular expression search and replace and it's suppose to be completed but I found a flaw and I'm stuck.

What my search and replace does is, file the 'title' attributes in html tags and convert them to a mouseover javascript. e.g:

Code:
        <a href="http://website.com" title="That's website">
        <a href='http://another.com' title='This website'>
        <hr title="Horizontal Ruler" />
        <hr title="No space"/>
I hope you understand the differences in the 4 tags (double quote, single quote, space and slash). My search and replace will make those tags into these:

Code:
        <a href="http://website.com" onMouseOver="overlib('That\'s website')">
         <a href='http://another.com' onMouseOver="overlib('This website')">
         <hr onMouseOver="overlib('Horizontal Ruler')" />
         <hr onMouseOver="overlib('No Space')"/>
It works well but the flaw is, when there is an empty title attributes,

Code:
        <a href="http://empty.com" title="">Empty</a><a href="http://null.com">null</a>
It will become this :-
Code:
        <a href="http://empty.com" onMouseOver="overlib('\">Empty</a><a href=')">"http://null.com">null</a>
Why?? Because it assumed in the title="", the second quote is the content which it should take, up to the next quote that arrive, which is href=".

Here's my regular expression code that I've made :-
PHP Code:
     $search  '/title=[\"|\'|](.+?)[\"|\'|](\s|\>|\/)/is';
      
$replace 'onmouseover="overlib(\' ' addslashes('$1') . ' \')" $2';
      
$content preg_replace($search,$replace,$content); 
$1 is the content inside the title attribute and $2 is the end part of it, be it a space,
closing angle bracket (>) or a slash.

To further explain my regular explression, the [\"|\'|] will look for the quote in the attributes. The (.+?) gets the content in between the next
[\"|\'|]. And the (\s|\>|\/) looks for space, closing angle bracket (>) or slash.

Thanks for your help..
__________________
Mr. Brown Eyes

Last edited by eddyvlad; 01-08-06 at 09:22 PM.
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression help zoic PHP 4 12-02-05 07:15 PM
regular expression for parsing url link musmanm80 Perl 1 07-28-05 12:58 AM
Regular Expression KHWright Visual Basic 0 06-02-05 07:40 PM
HELP!!! - Invalid preceding regular expression CMIVXX PHP 1 01-04-05 04:55 AM
suggest a regular expression gmadhukarreddy Perl 2 01-08-04 01:56 AM


All times are GMT -5. The time now is 03:16 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)