I have a text like this:
aaaljhgh
bbbgfdhd
cccasdsc
ddddadeqw
ebadew
I want to take Line 3 or Line 5 using PHP. How can I do it?
You can use explode()
command by "\n" , and get your texts in array (line by line).
See following example:
<?php
$text = $_POST['text'];
if ( $text ) {
$arr = explode("\n", $text);
echo "Line 3: " . $arr[2];
echo "<hr/>";
echo "Line 5: " . $arr[2];
}
?>
<form method="post">
<textarea name="text"></textarea>
<input type="submit" value="send" />
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.