Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   i'm stuck in counting new lines PHP (http://www.greenguysboard.com/board/showthread.php?t=63814)

pc 2012-04-18 06:05 PM

i'm stuck in counting new lines PHP
 
So I have a $ckeys['keywords'] string, (extract from head meta keywords ) that pretty much looks like this:

word
word
word
word
and so on, depends how many keywords there is.

Now I wrapped every new line into a separate

paragraph.

Quote:

" . str_replace("\n", "

", $ckeys['keywords']) . "

"; ?>
What I would like to have is to have a counter for each new line and use this counter for id='cell1' so I could have id='cell1', id='cell2', id='cell3' ...

Anyone ?



:)

cd34 2012-04-18 07:34 PM

Code:


$ckeys['keywords'] = array('word1','word2','word3','word4');
$loop = 1;
foreach ($ckeys['keywords'] as $word) {
  printf("

%s

\n", $loop, $word);
  $loop++;
}


flowersgone 2012-04-19 06:54 AM

I think sparky's answer is good but addresses a slightly different question. Perhaps this is closer to the question as posed:

Code:

$ckeys = array();
$ckeys['keywords'] = << word1
word2
word3
word4
EOT;

foreach (explode("\n", $ckeys['keywords']) as $i => $w) {
    $id = "cell" . ($i+1);
    echo "

$w

\n";
}
?>

fg

cd34 2012-04-19 11:13 AM

Quote:

Originally Posted by flowersgone (Post 515478)
I think sparky's answer is good but addresses a slightly different question. Perhaps this is closer to the question as posed:

You are correct, I assumed that the words were actually in his keywords array.

pc 2012-04-19 01:59 PM

thank you guys |thumb
I'll test this tonight.

pc 2012-04-19 03:34 PM

I already had keywords in array. But it works. Both cd34 and flowersgone without array works. Thanks again.


All times are GMT -4. The time now is 08:40 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc