verus Posted April 8, 2009 Share Posted April 8, 2009 I have run into a problem and I can't seem to figure it out. It is probably simple, but I am fairly new to Web Development. Basically what I am trying to do is search an xml document, but I don't even know where or how I would put the regular expression. I will explain more after the code (I know, this is probably really ugly and weird code): <?php $search = trim($_POST['search']); $xml = simplexml_load_file('Documents.xml'); $i=0; ?> <html> <head></head> <body> <h1>Search Results for: <?php print $search; ?> </h1> <table> <?php foreach ($xml->document as $document) { if($search == (string) $document->documentName) { ?> <tr><td><?php print $document->documentName; ?></td><td><a href="<?php print $document->documentLocation; ?>"><?php print $document->documentLocation; ?></a></td></tr> <?php $i++; } } ?> </table> <?php if($search !=(string) $document->documentName) { while($i == 0) { $i++; print 'No Results for ' . $search . ' found.'; } } ?> </body> </html> I have it so it will search the XML file and pull out anything that matches $search, but what I am trying to figure out is how I would 1) write a regular expression for $search. I am thinking something simple like just throwing % in the beginning and end of the variable. More importantly 2) where I would put it so that it will search the regular expression with the variable rather than just the variable. Any help would be greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/153108-php-xml-and-regular-expressions/ Share on other sites More sharing options...
eiledon01 Posted April 9, 2009 Share Posted April 9, 2009 I dont think you need to use regular expressions, although that might be more flexible. Quickest way might be to try ..... if(eregi($string,(string) $document->documentName)){ .... } Quote Link to comment https://forums.phpfreaks.com/topic/153108-php-xml-and-regular-expressions/#findComment-805848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.