-4

I have:

$string = "Some minimal or large text 820 some minimal or large descr";

I need:

some minimal or large descr 
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
tsla
  • 1
  • 2

3 Answers3

1

What about str_pos()?

<?php
  $string = "Some minimal or large text 820 some minimal or large descr";
  echo substr($string, strpos($string, '820') + 4);
LF00
  • 27,015
  • 29
  • 156
  • 295
  • 820 - for example. String always start from one or more words, numbers can be 1-100000 and one or more words after numbers. I need to get only words after numbers – tsla Apr 15 '17 at 12:10
  • if so, you can use preg_match, or you can split string to words array, then find the first number. – LF00 Apr 15 '17 at 12:17
  • I don't understand how to use preg_match for my situation. Can you give me example that I need? – tsla Apr 15 '17 at 12:20
1

The function preg_split can do for you!

It splits the string into an array transforming it ..

http://www.php.net/manual/en/function.preg-split.php

$array = preg_split("/[0-9]+/", "Some minimal or large text 820 some minimal or large descr");
print_r($array);
Pinguto
  • 416
  • 3
  • 17
0

To isolate some minimal or large descr which comes after the space that follows 820, match all non-digital characters from the start of the string until one or more digits, then zero or more spaces. Replace these matched characters with an empty string.

Code: (Demo)

$string = "Some minimal or large text 820 some minimal or large descr";

var_export(
    preg_replace('/\D*\d+ */', '', $string)
);

If multiple numbers may occur and you want the substring after the last occurring number, then greedily match any character before matching a number. (Demo)

var_export(
    preg_replace('/.*\d+ */', '', $string)
);
mickmackusa
  • 43,625
  • 12
  • 83
  • 136