title: Php get value from text file
body: <p>I have this textfile:</p>
  
  <pre><code>foo: bar
  el: macho
  bing: bong
  cake color: blue berry
  mayo: ello
  </code></pre>
  
  <p>And I what I'm trying to accomplish is that if I "look" for foo, it returns bar (if I look for bing, it should return bong). A way a tried to accomplish this is first search though the file, return the line with the result, put it in a string and remove everything before the ":" and display the string.</p>
  
  <pre><code>// What to look for
  $search = 'bing';
  // Read from file
  $lines = file('file.txt');
  foreach($lines as $line)
  {
      // Check if the line contains the string we're looking for, and print if it does
      if(strpos($line, $search) !== false)
          echo $line;
  
      $new_str = substr($line, ($pos = strpos($line, ',')) !== false ? $pos + 1 : 0);
  } 
  echo "&lt;br&gt;";
  echo "bing should return bong:";
  echo $new_str;
  </code></pre>
  
  <p>But it doesn't work. Up here is just one of the many things I've tried.</p>
  
  <p>Sources:
  Many stackoverflow links on and comparable searches:<br>
  <a href="https://www.google.com/search?client=opera&amp;q=php+remove+everything+after" rel="nofollow">https://www.google.com/search?client=opera&amp;q=php+remove+everything+after</a><br>
  <a href="https://www.google.com/search?client=opera&amp;q=php+search+text+file+return+line" rel="nofollow">https://www.google.com/search?client=opera&amp;q=php+search+text+file+return+line</a></p>
  
  <p>I've asked a question before, but the answers are to "professional" for me, I really need a noob-proof solution/answer. I've been trying to figure it out all day but I just can't get this to work.</p>
  
  <p>Edit:
  It's solved! Thank you so much for your time &amp; help, I hope this might be useful to someone else to!</p>