0

i have the folowing code that gives me the first letter of each word.

$string = $rowec['doopnamen'];
                    $punt =".";
$words = explode(" ", $string);
$doopnamen = " ";
foreach ($words as $value) {

    $doopnamen .= substr($value, 0, 1);

}

But how can i get a dot after each letter ?
Thanks in advice John

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by johnnyd1963
0

Not tested, but try:

$words = explode(',', implode('.,', $string));

this gives you an array again, if you want just a string then use just implode('.', $string).

Edit___
Or:

foreach($words as $value) { $doopnamen .= substr($value, 0, 1).'.'; }

so, if $string:

$string = 'alfa beta';

from the loop you get a.b. It was this you needed? Bye!

Edited by cereal

0

Thanks for your help Cereal

$words = explode(',', implode('.,', $string));

Gives an error

But

foreach($words as $value) { $doopnamen .= substr($value, 0, 1).'.'; }

Works great.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.