Jump to content

Lines


Guest Thunderhawk66

Recommended Posts

Guest Thunderhawk66
I have a script that uses a Regular Expression to get data from a textarea.

For example:

[code]preg_match_all("/Address:.[^\\n]*/i", $str, $matches);
foreach ($matches as $val) {
echo $val[1];
}[/code]

but I was wondering if there is a way to print a line of text two lines above it?

Eg if there is this text:

Hello
Blah
Address: 123

and the code prints "Address: 123", how would I get it to print the text two lines above it ("Hello")?

Thanks,
-Thunderhawk66.
Link to comment
https://forums.phpfreaks.com/topic/8684-lines/
Share on other sites

Guest Thunderhawk66
That sounds like it should work, thanks.
But could you maybe give an example?
I don't understand what you mean by "lets say it was line in "n"".
Here's some of the code I have:

[code]$str = nl2br(rtrim($_POST[text]));
$num = 0;
$i = 0;
while ($i < 200)
{
preg_match_all("/Address:.[^\\n]*/i", $str, $matches);
foreach ($matches as $val) {
$txtol = $val[$num];
$expl = explode("<br />", $txtol);
echo $expl[$num-2];
}
}
$i++;
$num++;
[/code]

Is that the way I do it?
Thanks for your help.
Link to comment
https://forums.phpfreaks.com/topic/8684-lines/#findComment-32044
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.