Jump to content

[SOLVED] Wildcards in IF statements and strings in text files


dragunu

Recommended Posts

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!
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 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 10

Fatal 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.