|
2012-04-18, 06:05 PM | #1 | |
Shift Out / X-On
|
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 <p> paragraph. Quote:
Anyone ? |
|
2012-04-18, 07:34 PM | #2 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
Code:
<?php $ckeys['keywords'] = array('word1','word2','word3','word4'); $loop = 1; foreach ($ckeys['keywords'] as $word) { printf("<p id='cell%d'>%s</p>\n", $loop, $word); $loop++; }
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
2012-04-19, 06:54 AM | #3 |
Are you sure you're an accredited and honored pornographer?
Join Date: Sep 2008
Posts: 67
|
I think sparky's answer is good but addresses a slightly different question. Perhaps this is closer to the question as posed:
Code:
<?php $ckeys = array(); $ckeys['keywords'] = <<<EOT word1 word2 word3 word4 EOT; foreach (explode("\n", $ckeys['keywords']) as $i => $w) { $id = "cell" . ($i+1); echo "<p id='$id'>$w</p>\n"; } ?> |
2012-04-19, 11:13 AM | #4 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
You are correct, I assumed that the words were actually in his keywords array.
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
2012-04-19, 01:59 PM | #5 |
Shift Out / X-On
|
thank you guys
I'll test this tonight. Last edited by pc; 2012-04-19 at 02:05 PM.. |
2012-04-19, 03:34 PM | #6 |
Shift Out / X-On
|
I already had keywords in array. But it works. Both cd34 and flowersgone without array works. Thanks again.
|
|
|