Greenguy's Board WebcamWiz CRAZY $5,000 Reward Bonuses

WebcamWiz CRAZY $5,000 Reward Bonuses WebcamWiz CRAZY $5,000 Reward Bonuses WebcamWiz CRAZY $5,000 Reward Bonuses WebcamWiz CRAZY $5,000 Reward Bonuses WebcamWiz CRAZY $5,000 Reward Bonuses

Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2012-04-18, 06:05 PM   #1
pc
Shift Out / X-On
 
pc's Avatar
 
Join Date: Jul 2007
Location: unknown
Posts: 2,298
Send a message via ICQ to pc
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:
<?php echo "<p id='cell1'>" . str_replace("\n", "</p><p id='cell1'>", $ckeys['keywords']) . "</p>"; ?>
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 ?



pc is offline   Reply With Quote
Old 2012-04-18, 07:34 PM   #2
cd34
a.k.a. Sparky
 
cd34's Avatar
 
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
cd34 is offline   Reply With Quote
Old 2012-04-19, 06:54 AM   #3
flowersgone
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";
}
?>
fg
__________________
Thank you for checking out my:
Portfolio and Tech Services
flowersgone is offline   Reply With Quote
Old 2012-04-19, 11:13 AM   #4
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
Quote:
Originally Posted by flowersgone View Post
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.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2012-04-19, 01:59 PM   #5
pc
Shift Out / X-On
 
pc's Avatar
 
Join Date: Jul 2007
Location: unknown
Posts: 2,298
Send a message via ICQ to pc
thank you guys
I'll test this tonight.

Last edited by pc; 2012-04-19 at 02:05 PM..
pc is offline   Reply With Quote
Old 2012-04-19, 03:34 PM   #6
pc
Shift Out / X-On
 
pc's Avatar
 
Join Date: Jul 2007
Location: unknown
Posts: 2,298
Send a message via ICQ to pc
I already had keywords in array. But it works. Both cd34 and flowersgone without array works. Thanks again.
pc is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:17 AM.


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