Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   custom php based matching function (http://www.go4expert.com/forums/custom-php-based-matching-function-t22944/)

pein87 6Aug2010 11:19

custom php based matching function
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.

pein87 6Aug2010 14:15

Re: custom php based matching function
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.

johnny.dacu 6Aug2010 23:49

Re: custom php based matching function
Why do you want to reinvent the wheel? PHP is already an XML parser, even a DOMDocument library for html ...

pein87 8Aug2010 01:50

Re: custom php based matching function
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.

haamid 8Aug2010 16:19

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

pein87 8Aug2010 23:40

Re: custom php based matching function
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.

All times are GMT +5.5. The time now is 17:22.