10 Replies - 3853 Views - Last Post: 21 January 2012 - 08:28 AM Rate Topic: -----

#1 Xx4everxX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 12

[Question] Find a string with a word inside it

Posted 20 January 2012 - 08:37 AM

I need your help
I have a text file, this is it
Manifest-Version: 1.0
MIDlet-Vendor: Wap Master
Ant-Version: Apache Ant 1.8.2
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-1: Clip Nong Bong,/icon.png, LinkVip
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
MIDlet-Name: Clip
MicroEdition-Profile: MIDP-2.0 


I only want to get this string
 MIDlet-1: Clip Nong Bong,/icon.png, LinkVip

I could find it by world "MIDlet-1"
But i dont know to get the string i want
Please help me, thanks

Is This A Good Question/Topic? 0
  • +

Replies To: [Question] Find a string with a word inside it

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2911
  • View blog
  • Posts: 10,079
  • Joined: 08-August 08

Re: [Question] Find a string with a word inside it

Posted 20 January 2012 - 09:51 AM

You could do:
$some_array = file("your_file.txt");

and then search the array for a line that starts with those characters.
Was This Post Helpful? 0
  • +
  • -

#3 kdye101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-September 09

Re: [Question] Find a string with a word inside it

Posted 20 January 2012 - 10:36 AM

I would say to use the method described above.

Try writing it out like this.
Load file into an array
For each line in the array
Search the line for the string
If the string exists, set $var = line and exit
Else do error stuff
Was This Post Helpful? 0
  • +
  • -

#4 Xx4everxX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 12

Re: [Question] Find a string with a word inside it

Posted 20 January 2012 - 03:35 PM

View PostCTphpnwb, on 20 January 2012 - 09:51 AM, said:

You could do:
$some_array = file("your_file.txt");

and then search the array for a line that starts with those characters.

Please help me, i need to find and display this line
Could you give me a full code? Thank
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2911
  • View blog
  • Posts: 10,079
  • Joined: 08-August 08

Re: [Question] Find a string with a word inside it

Posted 20 January 2012 - 08:26 PM

No. Read the rules and follow them.
Was This Post Helpful? 0
  • +
  • -

#6 Xx4everxX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 12

Re: [Question] Find a string with a word inside it

Posted 20 January 2012 - 11:05 PM

Ok my script
 <html>
<head><title>Searching for lines beginning with a word</title></head>
<body>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="str"
    value="<?php print $_POST['str'];?>" /><br />
<input type="submit" value="Find lines" /><br /><br />
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" )
{
    $str = $_POST['str'];
    if ( preg_match( "/^Word\b/", $str ) )
    {
        print "<b>Found a match!: &amp;nbsp;'". $str . "'</b><br/>";
    } else {
        print "<b>Didn't find it: &amp;nbsp;'". $str . "'</b><br/>";
    }
}
?>
</form>
</body>
</html> 

But it only find the word if match, not display the line start with this word
Please help me to fix it, thanks
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: [Question] Find a string with a word inside it

Posted 21 January 2012 - 04:52 AM

Show an example of what it's outputting, and what you expect it to output.
Was This Post Helpful? 0
  • +
  • -

#8 Xx4everxX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 12

Re: [Question] Find a string with a word inside it

Posted 21 January 2012 - 04:59 AM

Colud you tell me how to remove down-line word from a string?
Ex
I love you
I Hate You

Will become
I love youI hate you

Thanks
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2911
  • View blog
  • Posts: 10,079
  • Joined: 08-August 08

Re: [Question] Find a string with a word inside it

Posted 21 January 2012 - 06:43 AM

See this.
Was This Post Helpful? 0
  • +
  • -

#10 Xx4everxX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 12

Re: [Question] Find a string with a word inside it

Posted 21 January 2012 - 06:52 AM

This is my code
$string = str_replace('\n', '', $text);


But it not work
Please hepl :-)
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2911
  • View blog
  • Posts: 10,079
  • Joined: 08-August 08

Re: [Question] Find a string with a word inside it

Posted 21 January 2012 - 08:28 AM

Try this:
<?php
$text = <<<HERE
Sample 
text.
HERE;

$string = str_replace('\n', '', $text);

$other_string = str_replace("\n",'', $text);

echo "<pre>".$string."\n\n".$other_string."</pre>";
?>

What happens, and why?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1