[ create a new paste ] login | about

Link: http://codepad.org/220BLjEk    [ raw code | output | fork ]

PHP, pasted on May 7:
<?php

//this is the content
$text = 'Title: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Category: Lorem ipsum dolor sit amet, consectetur adipiscing elit.';

//get the lines from your input as an array.. you could acheive this in a different way if, for example, you are reading from a file
$lines = explode(PHP_EOL, $text);

// apply a cusom function to filter the lines (remove the ones that don't match your rule)
$results = array_filter($lines, 'test_content');

//show the results
print_r($results);

//custom function here:
function test_content($line)
{
	//case insensitive search, notice stripos; 
	// type strict comparison to be sure that it doesn't fail when the element is found right at the start
	if (false !== stripos($line, 'Snippet'))
	{
		return true;
	}
	return false;//these lines will be removed 
}


Output:
1
2
3
4
Array
(
    [1] => Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
)


Create a new paste based on this one


Comments: