custom php based matching function

Discussion in 'PHP' started by pein87, Aug 6, 2010.

  1. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    I've been wondering if its feasible to make a php based core function only matching program. I dont want to use regex but make a custom matching function which could be implemented in a custom parser for xml. My ideas so far is to use file_get_contents() to provide the file as a source, then get the full length of characters of the file and then iterate using a for loop to search for every matching instance of the needle in the haystack. Any ideas how one would go about doing this with the ability to tokenize then matches? I know reinventing the wheel but regex can be complicated and does not suit context-free grammar parsing. The parser in question would read a files, transform it into php code thats serialized when its stored and then either matches the instances of the elements of builds a php code tree view of the xml doc.
     
  2. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    I found that using file_get_contents() and storing it as a variable and then use strlen() on that variable will give me the length of the files since its stored as a string, all that would be next is to give it commands to ignore white space and the ability to recognize new lines, it would probably be a multi-pass function that does checks for new lines first and then does the matching so I can possibly add the feature to count new lines.
     
  3. johnny.dacu

    johnny.dacu New Member

    Joined:
    Jul 6, 2010
    Messages:
    88
    Likes Received:
    4
    Trophy Points:
    0
    Why do you want to reinvent the wheel? PHP is already an XML parser, even a DOMDocument library for html ...
     
  4. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    Because the saying "why reinvent the wheel" shows a lack of wanting to understand how things work and that your statisfied with the current ugly syntax of regex. If we never try to reinvent the wheel then we would never find better solutions to the same problem and programmers are problems solvers. The parser in question would one, read a directory for language definitions, two parse those files and convert then into an array and save them as either a txt file or a php file for performance, and then allow you to replace instances of the language in other files with what you what it to be. It would replace the confusing regex preg_match() and preg_replace() syntax with something that easier. I know using the dom extension would be great for xml but my parser would be for mark up languages in general like bbcodes, xml, and html. Thats what i want to make a php based matching function that easy to use and does not require the users of it to remember tedious signs and symbols for replacing and matching. If I can get it working at a good enough speed I might make it a php extension, I'm using C pattern matching source code as a start point since C and php share similar functions. If you have any ideas it would greatly be appreciated in helping me with the pattern matching/string matching program using php string fucntions.
     
  5. haamid

    haamid New Member

    Joined:
    Aug 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    counter

    Please check error on my script this is working on my computer server
    and not working on my web server.:confused:
    Email: hamid.3pk gmail .com
     
  6. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    I found a site with a php example in a short sense but I need to tweek the code to work better and faster

    Once its doen and working right I'll release it here for those who want to test it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice