Get everything after word

前端 未结 4 1967
迷失自我
迷失自我 2021-01-05 08:02

Take this Lorem Ipsum text:

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

相关标签:
4条回答
  • 2021-01-05 08:12
    /Nulla(.*)/
    

    Now you have all the text after Nulla in $1

    0 讨论(0)
  • 2021-01-05 08:22

    Hmm you don't want to use some simple things like :

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

    if you do not want to look for Nulla, but also for 'null' you might consider using stripos instead of strpos... This code will include Nulla in the returned value. If you want to exclude Nulla, you might want to add it's lentgh to the strpos value i.e

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

    At last, if you need to have something a bit more generic, and as suggested @Francis :

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

    Honestly regexp are overkill for something like this...

    0 讨论(0)
  • 2021-01-05 08:30

    Try this:

    $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);
    
    0 讨论(0)
  • 2021-01-05 08:31
    $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 讨论(0)
提交回复
热议问题