alphacooler
Programmer
I would like to wrap <li></li> tags around each newline.
How would I go about this?
How would I go about this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
This is some text
With Some line brakes
and some other lines
and another one.
$textvariable="This is some text..."; [green]\\variable that contains the string to convert.[/green]
$output=str_replace("[red]\n\r[/red]","</li><li>",$texvariable);
[green]\\replace the carriage returns or end of line with the <li></li> html for the lists."\n\r" are the characters for carriage return or new line [/green]
$output="<ul><li>" . $output ."</li></ul>";
[green]Finally add the beggining and ending <li> and if neccessary the <ul> and </ul> tags for the proper output of the list.[/green]
<?php
$a='this is some text
this is text2
this is line 3
this is part4
this is the last line';
$search[0]='/^/';
$search[1]='/\n/';
$search[2]='/$/';
$repl[0]='<li>';
$repl[1]='</li><li>';
$repl[2]='</li>';
$b=preg_replace($search,$repl,$a);
echo "$b";
?>