Jump to content
php.lv forumi

for each line ?


Swear

Recommended Posts

Tātad ir dots $teksts kas satur vairākas rindiņas

$teksts = 'Rinda 1
Rinda 2
Vel kautkas
Un ta talak';

Vajadzētu apstrādāt katru rindiņu piemēram kā ar foreach ($lines as $line_num => $line) bet šis sanāk tikai nolasot failu.

 

Kādi ieteikumi?

Link to comment
Share on other sites

Tātad ir dots $teksts kas satur vairākas rindiņas

$teksts = 'Rinda 1
Rinda 2
Vel kautkas
Un ta talak';

Vajadzētu apstrādāt katru rindiņu piemēram kā ar foreach ($lines as $line_num => $line) bet šis sanāk tikai nolasot failu.

 

Kādi ieteikumi?

 

$arr = explode("\r\n",$teksts); //\r\n vai \n
foreach($arr as $line => $item){
echo ($line + 1) . ". rindiņā ir teksts: $item<br />";
}

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...