Get everything after the word

Take this text by Lorem Ipsum:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla felis diam, mattis id elementum eget, ullamcorper et purus.

How can I get everything that comes after Nulla with PHP and regular expression?

+4
source share
4 answers

Hmm, you do not want to use some simple things, for example:

 $str = substr($lorem, strpos($lorem, 'Nulla')); 

if you do not want to search for Nulla, but also for "null", you can use stripos instead of strpos ... This code will include Nulla in the return value. If you want to exclude Nulla, you can add lentgh to the strpos value

Honestly, regexp are redundant for something like this ...

+18
source
 /Nulla(.*)/ 

Now you have all the text after Nulla at $ 1

+3
source

Try the following:

 $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla felis diam, mattis id elementum eget, ullamcorper et purus."; $prefix = "Nulla"; $index = strpos($string, $prefix) + strlen($prefix); $result = substr($string, $index); 
+2
source
 $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla felis diam, mattis id elementum eget, ullamcorper et purus.'; preg_match('/Nulla(.*)/',$string, $matches); print_r($matches); 
0
source

All Articles