¿Cómo usar php para reemplazar puntos con viñetas (li)?

I have a string in php with multiple periods. I am trying to figure out to replace each of the periods in the string into a bullet (<li>) on a new line. Does anyone have advice on how to do this?

$desc= "Petite Jeans. Petite Fit Guide,Tall Fit Guide Explore our 1969 denim boutique for fit facts, fabric notes, style tips, and more. Fabrication: Premium stretch denim. Wash: Faded dark blue. Hardware: Double button closure, zip fly. Features: Five pocket styling. Cut: Mid rise. Fit: Slim through the hip and thigh. Leg opening: Boot cut. Inseams: regular: 33\', tall: 37\', petite: 30\'";

echo $desc;

The above string should look like:

<li>Petite Jeans. 
<li>Petite Fit Guide,Tall Fit Guide Explore our 1969 denim boutique for fit facts, fabric notes, style tips, and more. 
<li>Fabrication: Premium stretch denim. 
<li>Wash: Faded dark blue. 
<li>Hardware: Double button closure, zip fly. 
<li>Features: Five pocket styling. 
<li>Cut: Mid rise. 
<li>Fit: Slim through the hip and thigh. 
<li>Leg opening: Boot cut. 
<li>Inseams: regular: 33\', tall: 37\', petite: 30\'

preguntado el 01 de febrero de 12 a las 03:02

i could provide a solution easy enough so long as there was only ever a period at the end of each line and not more than one on a line. is this the case ? -

3 Respuestas

As long as you're sure that every period can be replaced, what you want is implode() y la explode():

$desc = '<li>' . implode('</li><li>', explode('.', $desc)) . '</li>';

Respondido 01 Feb 12, 07:02

Utilizan str_replace:

$desc = '<li>' . str_replace('.','</li><li>', $desc) . '</li>';

http://ideone.com/Z62S5

Respondido 01 Feb 12, 08:02

Has probado

$bulletted = str_replace(".", "<br />&bull;", $desc);

Consulte nuestra página http://php.net/manual/en/function.str-replace.php

Respondido 01 Feb 12, 07:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.