-2

I have a string which contains :

navigation pane or double clicking folders in the details pane.

Navigating the folder structure
-------------------------------
symbol will expand or collapse folders in the navigation pane

I want to extract text only "Navigating the folder structure"

I have tried with preg_match_all but unable to handle starting point which is a new line.

I also tried with strpos but unable to do with new line as starting point.

Dan
  • 9,391
  • 5
  • 41
  • 73
Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
  • Did you try `strpos`? http://stackoverflow.com/questions/4366730/how-to-check-if-a-string-contains-a-specific-word-in-php – Dan Dec 19 '16 at 05:55
  • I tried that but how to handle new line in strpos ? – Naveed Ramzan Dec 19 '16 at 05:57
  • so what's the condition do you judge which string should be extract? the following "`------------------`"? – Fu Xu Dec 19 '16 at 06:05
  • It can be started from a new line and should be ending at --------, so as per question's string. it will be Navigating the folder structure. But I need to do this dynamic so what ever the text it contains that should be extracted. – Naveed Ramzan Dec 19 '16 at 06:06

2 Answers2

1

Use a combination of strpos to find the line breaks, and substr to extract the text between the first and second line break. This text includes the dashes (-) so I included a str_replace to remove them.

$string = 'navigation pane or double clicking folders in the details pane.

    Navigating the folder structure
    -------------------------------
    symbol will expand or collapse folders in the navigation pane';

$position1 = strpos($string, "\n");
$position2 = strpos($string, "\n",$position1);

$extracted = str_replace("-","",substr($string, $position1, $position2));

echo $extracted;

This will print the desired text

Dan
  • 9,391
  • 5
  • 41
  • 73
0

Use explode -

$new =  explode("\n", $str);
var_dump($new[2]);
jitendrapurohit
  • 9,435
  • 2
  • 28
  • 39