Skip to content

Instantly share code, notes, and snippets.

@mrcat323
Created January 31, 2017 14:43
Show Gist options
  • Save mrcat323/b4b9c0cad40454985c51f461c9a73a27 to your computer and use it in GitHub Desktop.
Save mrcat323/b4b9c0cad40454985c51f461c9a73a27 to your computer and use it in GitHub Desktop.
<?php
$text = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
function getWordsCountEndsWith($letter, $text)
{
return preg_match_all('#' . preg_quote($letter, '#') . '\b#usi', $text);
}
function getWordsCountStartsWith($letter, $text)
{
return preg_match_all('#\b' . preg_quote($letter, '#') . '#usi', $text);
}
var_dump(getWordsCountEndsWith('g', $text));
var_dump(getWordsCountStartsWith('h', $text));
var_dump(getWordsCountStartsWith('l', $text));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment