How to filter out the numbers from a post title
-
I just need some php code that would be able to filter out the numbers from the post title in a loop
For example this loop here
<?php foreach($posts as $post)
{ … } ?>My post titles look like the following
blah blah blah blah blah blah 24
blah blah blah blah 123-124
blah blah blah blah blah 23These numbers will always appear at the end of the post title.
So basically if there is a function that will look for the first number it finds in the post title, and then print everything after that would definitely work for my scenario.
I tried using the substr function, but that won’t work when you have different amounts of digits to print.
There’s always the preg_match, but it’s not showing me the results I want when I use a code like the following
<?php $posttitle = the_title(”,”,false);
$pattern = ‘/[0-9]/’;
preg_match($pattern, $posttitle, $matches);
echo $matches[0];
?>
- The topic ‘How to filter out the numbers from a post title’ is closed to new replies.