laavanya14 Posted April 14, 2006 Share Posted April 14, 2006 Hi Guys,I would to know how to find for a particular keyword in a string.Example, i would like to have all the the words include('XXXX') in the string in an array.It doesnt matter what is inside the bracket of the include statementI checked out the preg_match manual, but not really sure how to use it.Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
bonaparte Posted April 14, 2006 Share Posted April 14, 2006 [!--quoteo(post=364707:date=Apr 14 2006, 12:56 AM:name=Laavanya)--][div class=\'quotetop\']QUOTE(Laavanya @ Apr 14 2006, 12:56 AM) [snapback]364707[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi Guys,I would to know how to find for a particular keyword in a string.Example, i would like to have all the the words include('XXXX') in the string in an array.It doesnt matter what is inside the bracket of the include statementI checked out the preg_match manual, but not really sure how to use it.Thanks in advanced.[/quote]Sorry, it is a bit difficult to understand the query. preg_match() matches an regular expression in a string and can store the results in an array.Could you expain your example with more information? If you can tell us what exactly do you want to do, we might help you with the code. Quote Link to comment Share on other sites More sharing options...
laavanya14 Posted April 14, 2006 Author Share Posted April 14, 2006 Helo thanks for the reply.Assuming i have a [code]$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); " [/code]so i want all the filename inside the include in the string in an array is possible.meaning array[0] = test.php array[1] = pooh.phpthanks in advanced Quote Link to comment Share on other sites More sharing options...
bonaparte Posted April 14, 2006 Share Posted April 14, 2006 [!--quoteo(post=364714:date=Apr 14 2006, 01:43 AM:name=bonaparte)--][div class=\'quotetop\']QUOTE(bonaparte @ Apr 14 2006, 01:43 AM) [snapback]364714[/snapback][/div][div class=\'quotemain\'][!--quotec--]Sorry, it is a bit difficult to understand the query. preg_match() matches an regular expression in a string and can store the results in an array.Could you expain your example with more information? If you can tell us what exactly do you want to do, we might help you with the code.[/quote]See if this works for you:$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); "; $pattern = "/([a-z])*\.php/"; $subject = $mystring; preg_match_all($pattern, $subject, $matches); print_r($matches);[!--quoteo(post=364746:date=Apr 14 2006, 05:40 AM:name=bonaparte)--][div class=\'quotetop\']QUOTE(bonaparte @ Apr 14 2006, 05:40 AM) [snapback]364746[/snapback][/div][div class=\'quotemain\'][!--quotec--]See if this works for you:$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); "; $pattern = "/([a-z])*\.php/"; $subject = $mystring; preg_match_all($pattern, $subject, $matches); print_r($matches);[/quote]Sorry, the below code seems to be more effective:$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); "; $pattern = "/[a-zA-Z]+\.php/"; $subject = $mystring; preg_match_all($pattern, $subject, $matches); print_r($matches); foreach ($matches as $value) { $targetarray = $value; } echo "<br> target array "; print_r($targetarray); Quote Link to comment Share on other sites More sharing options...
laavanya14 Posted April 14, 2006 Author Share Posted April 14, 2006 [!--quoteo(post=364746:date=Apr 14 2006, 05:46 AM:name=bonaparte)--][div class=\'quotetop\']QUOTE(bonaparte @ Apr 14 2006, 05:46 AM) [snapback]364746[/snapback][/div][div class=\'quotemain\'][!--quotec--]See if this works for you:$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); "; $pattern = "/([a-z])*\.php/"; $subject = $mystring; preg_match_all($pattern, $subject, $matches); print_r($matches);Sorry, the below code seems to be more effective:$mystring = "this is a include('test.php'). I would like to test include('pooh.php'); "; $pattern = "/[a-zA-Z]+\.php/"; $subject = $mystring; preg_match_all($pattern, $subject, $matches); print_r($matches); foreach ($matches as $value) { $targetarray = $value; } echo "<br> target array "; print_r($targetarray);[/quote]helo, thank you so very much.however there is a constraint here.i only want the statement printed if it is inside the include statement. besides it not neccesary be a php file. it might be a html file.the particular code would even print out even if the filename isnt inside the include function.basically what i am trying to do here, is to parse the string and check for the included files.thanks again Quote Link to comment Share on other sites More sharing options...
bonaparte Posted April 14, 2006 Share Posted April 14, 2006 [!--quoteo(post=364749:date=Apr 14 2006, 05:53 AM:name=Laavanya)--][div class=\'quotetop\']QUOTE(Laavanya @ Apr 14 2006, 05:53 AM) [snapback]364749[/snapback][/div][div class=\'quotemain\'][!--quotec--]helo, thank you so very much.however there is a constraint here.i only want the statement printed if it is inside the include statement. besides it not neccesary be a php file. it might be a html file.the particular code would even print out even if the filename isnt inside the include function.basically what i am trying to do here, is to parse the string and check for the included files.thanks again[/quote]Please keep reading this till I get time to write the complete code for you.[a href=\"http://in2.php.net/preg_match\" target=\"_blank\"]http://in2.php.net/preg_match[/a]and[a href=\"http://www.google.co.in/search?q=regular+expressions\" target=\"_blank\"]http://www.google.co.in/search?q=regular+expressions[/a] Quote Link to comment Share on other sites More sharing options...
laavanya14 Posted April 14, 2006 Author Share Posted April 14, 2006 [!--quoteo(post=364751:date=Apr 14 2006, 05:59 AM:name=bonaparte)--][div class=\'quotetop\']QUOTE(bonaparte @ Apr 14 2006, 05:59 AM) [snapback]364751[/snapback][/div][div class=\'quotemain\'][!--quotec--]Please keep reading this till I get time to write the complete code for you.[a href=\"http://in2.php.net/preg_match\" target=\"_blank\"]http://in2.php.net/preg_match[/a]and[a href=\"http://www.google.co.in/search?q=regular+expressions\" target=\"_blank\"]http://www.google.co.in/search?q=regular+expressions[/a][/quote]hi again..thank you very much again.i would check it out. i just dont understand how to set the conditions for the pattern thing inside the preg_match statement Quote Link to comment 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.