0

there is a php variable like this $variable='a b c d e f g h i j k l' is it possible to get the central line e f g h in the variable and remove the rest. provided that values of all three lines are unknown.

1 Answer 1

2

You can simply split the string, using the new line '\n' character

$mline = 'a b c d 
e f g h 
i j k l';
$your_array = explode("\n", $mline); 

echo $your_array[1]; //Specific solution
echo $your_array[ceil(count($your_array)/2)]; //General solution
Sign up to request clarification or add additional context in comments.

1 Comment

thank u problem is solved. your answer was really helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.