Results 1 to 6 of 6

Thread: Regular expressions and efficiency

  1. #1
    Administrator
    UK diades's Avatar
    Join Date
    Feb 2001
    Location
    Glasgow, Scotland
    Posts
    15,664
    Blog Entries
    6

    Regular expressions and efficiency

    Hi,

    Some time ago I wrote a script in php to read an xml stream, parse the data into the format that I required and present it to the user.

    For the most part, there are no problems but, there is one field of each record that does cause challenges. The data stream comes from a game that is played online called 'VSK5 America's cup challenge' and is a list of all registered players giving their login-names (no problem) and their 'boat-name' - problem!!!

    The boat name is allowed to be 'formatted' by the user both for bold,italic etc., and colour. The formatting uses the syntax shown here: http://vsk.diades.net/formatting.php and, as long as the formatting is used correctly all is ok but, these users are not all 'disciplined' as regards formatting and that is where the mess up occur. If you go here: http://www.diades.net/vsk-rankings.php where the script is in action there is, at the moment, a 'broken' name in the script that is causing a problem on the layout.

    The user
    Code:
    " K3y 77 - Poppy " "
    is obviously using unmatched quote makes (no rules for that) , here is the actual 'script for the login name shown:
    Code:
    $s $f00 " K3y 77 - Poppy " "
    Another as shown on the page:
    Code:
    ita_
    
    pa
    
    o
    LO $m$i$0f0 (v$fffsk$f03a$f00)
    As you see, most of the formatting in this instance is being ignored (perhaps because there are newline chars in there?. Again the actual unparsed login:
    Code:
    $0f0ITA_$fffPA$f00OLO $m$i$0f0 (v$fffsk$f03a$f00)
    $0f0ITA_$fffPA$f00OLO $m$i$0f0 (v$fffsk$f03a$f00)

    The red above showing the formatting codes.

    I have attached the file, the whole script requires upgrading from php4 to php5 which is on my todo list but it is the parsing of the formatting that is bugging me if anyone can help overcome the nasties.
    Attached Files Attached Files

  2. #2
    Moderator
    UK fivesidecube's Avatar
    Join Date
    Apr 2002
    Location
    North Yorkshire
    Posts
    748
    Could you use php's htmlspecialchars function to handle characters like "? (Somewhere around line# 152 in your sample code). I cut n paste your parseName method and tested it by calling it via
    Code:
    echo parseName('$s $f00 " K3y 77 - Poppy " "');
    and it appears to create a valid string:
    Code:
    <div style="display:inline;color:#"></div><div style="display:inline;color:#s "></div><div style="display:inline;color:#f00"> &quot; k3y 77 - poppy &quot; &quot
    ;</div>
    Last edited by fivesidecube; 11th June 2012 at 18:00.
    "You see, I have the key to the gates of paradise, but I've got too many legs!" - Jeff

  3. #3
    Moderator
    UK fivesidecube's Avatar
    Join Date
    Apr 2002
    Location
    North Yorkshire
    Posts
    748
    Quote Originally Posted by diades View Post
    As you see, most of the formatting in this instance is being ignored (perhaps because there are newline chars in there?. Again the actual unparsed login:
    Code:
    $0f0ITA_$fffPA$f00OLO $m$i$0f0 (v$fffsk$f03a$f00)
    When I try this code in your code I'm getting undefined errors for the $format on line# 194. I changed this to $arr[$i] and the following few lines appears to correct the error report and it produces something that appears to be (closer to) correct.
    Code:
    ....
    case "m": //normal setting 
      $arr[$i] = str_replace($arr[$i],"<div style=\"display:inline;letter-spacing:2px\">",$arr[$i]); $divsFlag++; break;
    case "t": //changes the text to capitals
    "You see, I have the key to the gates of paradise, but I've got too many legs!" - Jeff

  4. #4
    Administrator
    UK diades's Avatar
    Join Date
    Feb 2001
    Location
    Glasgow, Scotland
    Posts
    15,664
    Blog Entries
    6
    Hi Five

    One of the problems is that of consistency. A login name that parses this time will break next time. This makes me wonder if it is the parsing of the xml? There are, of course problems with the format parsing but if the data is scrambled getting there …

    One of the upgrades will be to replace the parsing with simple XML perhaps.

  5. #5
    Moderator
    UK fivesidecube's Avatar
    Join Date
    Apr 2002
    Location
    North Yorkshire
    Posts
    748
    I think that I'd add a little bit of code to the parseName method to write the passed parameters to file, excerise the the page a few times until the you see a fault and then check the file for the input used to create the page.

    That way you'll see if it's the input to parseName method is correct or bust.

    If it's always the same name, filter the output written to the file by the name, after which every line in the output file should be the same and if it's not, it'll be easy to id.
    "You see, I have the key to the gates of paradise, but I've got too many legs!" - Jeff

  6. #6
    Administrator
    UK diades's Avatar
    Join Date
    Feb 2001
    Location
    Glasgow, Scotland
    Posts
    15,664
    Blog Entries
    6
    Thanks my friend

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Other: Regular Expressions
    By George W. Bush in forum Server-side Forum
    Replies: 1
    Last Post: 11th August 2005, 11:20
  2. Regular Expressions
    By Operandi in forum Server-side Forum
    Replies: 2
    Last Post: 18th July 2005, 05:21
  3. regular expressions
    By kiran in forum Client-side forum
    Replies: 1
    Last Post: 19th April 2002, 20:36
  4. Regular Expressions
    By GSHelpBoy in forum Server-side Forum
    Replies: 2
    Last Post: 18th April 2002, 14:49
  5. JSP Regular Expressions
    By bdale in forum Server-side Forum
    Replies: 0
    Last Post: 19th November 2001, 13:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •