Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? If you have an account, sign in now.

If you don't have an account, apply for one now.

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorguur3k
    • CommentTimeJul 5th 2006 edited
     
    In case anyone out there is planning on making their very own "DBC Parser to MySQL" converter too, let this be the place to ask your questions or offer advice. I have not a question for this post but thought I would post a tidbit of code that others may find useful.



    DBC String Block parsing
    ----
    For sometime I was having a problem getting the full text from the string fields to show up when I parsed them. If the string has carriage returns the standard preg_match only will not work.

    Here's the code I *was* using:

    preg_match('/(.+?)["\x00"]/i',substr($string_block,$data_int,1500),$m);

    Simple enough. I get the string_block and determine my start point with the data_int and read 1,500 characters into it (may be a bit too much, may not, but I rather not read up to 7 meg's of code every loop) then find the first match with Any characters up to the NULL byte.

    Well this did not produce what I was expecting for I was losing some critical data.

    This code next is what remedy my problem:

    preg_match('/(.+?)["\x00"]/i',preg_replace("/\s\n/","\\n",substr($string_block,$data_int,1500)),$m);

    The same as above but with a replacement function for the carriage returns.
    • CommentAuthorFreddy
    • CommentTimeJul 5th 2006 edited
     
    s (PCRE_DOTALL)
    If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

    http://de3.php.net/manual/sv/reference.pcre.pattern.modifiers.php
    • CommentAuthorguur3k
    • CommentTimeJul 5th 2006 edited
     
    Yes, but it still was not being saved fully in the $match array so I just added it to the array as a single line of text with newlines as representation (\\n) instead of newlines (\n).


    edit: and now I can parse them from my database as newlines, as is, or preg_match them to (br /)'s.
    edit2: ha! also note this works perfect for INSERTing them to a sql database cause cause they are already esacaped.