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.
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.
Why do you want to reinvent the wheel? PHP is already an XML parser, even a DOMDocument library for html ...
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.
counter Please check error on my script this is working on my computer server and not working on my web server. Email: hamid.3pk gmail .com
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.