dragunu Posted December 31, 2006 Share Posted December 31, 2006 Hello dear phpfreaks community, I was wondering if it is possible in php to : 1) Convert this statement in php IF statement code: "IF the word "hello" is in the 2nd sentence then " Of course if ( "hello" == $array[$number_of_sentence] ) will not work since i only need to see if "hello" is within that sentence. 2) In PHP, does a particular identifier exist in order to split a particular sentence in a text file? will the split function work? Cause I only know how to extract the first word/chuck of characters in a sentence with the split function.Thanks beforehand :) and happy new year all! Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/ Share on other sites More sharing options...
Orio Posted December 31, 2006 Share Posted December 31, 2006 1)[code]<?phpif(strpos($text, "hello") !== FALSE) echo "hello was found";?>[/code].2) If I understood you well, the function you are looking for is [url=http://www.php.net/manual/en/function.file.php]file()[/url].Orio. Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150340 Share on other sites More sharing options...
ShogunWarrior Posted December 31, 2006 Share Posted December 31, 2006 I'm going to presume you have text like so:[code]This is some text.Hello, this is the second sentence. This is a third.[/code]The code to split the text ( $text )[code]$spl = explode( '.' , $text );if( isset($spl[1]) && strpos(strtolower($spl[1]),'hello') !== FALSE ){ //Hello is in the second sentence}[/code] Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150343 Share on other sites More sharing options...
dragunu Posted December 31, 2006 Author Share Posted December 31, 2006 cheers guys, will definately try these suggestions out ;) Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150365 Share on other sites More sharing options...
dragunu Posted December 31, 2006 Author Share Posted December 31, 2006 [quote author=ShogunWarrior link=topic=120480.msg494185#msg494185 date=1167572298]I'm going to presume you have text like so:[code]This is some text.Hello, this is the second sentence. This is a third.[/code]The code to split the text ( $text )[code]$spl = explode( '.' , $text );if( isset($spl[1]) && strpos(strtolower($spl[1]),'hello') !== FALSE ){ //Hello is in the second sentence}[/code][/quote]i am trying to workaround with this code:[code]<?php$filename = "test.txt";$file_array = file($filename); for($num=0;$num<count($file_array);$num++) { $line = trim($file_array[$num]); $text = $explode("." , trim($line) ); print $text[0]; } ?>[/code]however i am getting this error :[quote]Notice: Undefined variable: explode in c:\program files\easyphp1-8\www\indexo.php on line 10Fatal error: Call to undefined function: () in c:\program files\easyphp1-8\www\indexo.php on line 10[/quote]where line 10 is [code]$text = $explode("." , trim($line) );[/code]cnt find y $explode is not being defined:)thanks again :)drag Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150455 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2006 Share Posted December 31, 2006 The function is [b]explode()[/b], not [b][color=red]$[/color]explode()[/b].Ken Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150458 Share on other sites More sharing options...
dragunu Posted January 1, 2007 Author Share Posted January 1, 2007 [quote author=kenrbnsn link=topic=120480.msg494302#msg494302 date=1167591390]The function is [b]explode()[/b], not [b][color=red]$[/color]explode()[/b].Ken[/quote]lol. that was it!!thanks ken Link to comment https://forums.phpfreaks.com/topic/32374-solved-wildcards-in-if-statements-and-strings-in-text-files/#findComment-150757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.