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
Share on other sites

Guest Thunderhawk66
Thanks for that, but I meant if a user entered text in the textarea, and I found some text called "Address:", could I print the second line that was above it (if I didn't know what was entered).
That "Hello, Blah" was an example of what could be entered in the textarea.
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.