0

PHP pulls data from a table which is a list in HTML format:

<ul>
    <li>first line of text</li>
    <li>second line of text</li>
    <li>third line of text</li>
    <li>forth line of text</li>
    <li>fifth line of text</li>
    <li>sixth line of text</li>
    <li>seventh line of text</li>
</ul>

which is outputted by:

<?php echo $lines; ?>

However i would like to use a foreach so that i can take that list and output in the following format if possible

<span>first line of text</span>
<span>second line of text</span>
<span>third line of text</span>
<span>forth line of text</span>
<span>fifth line of text</span>
<span>sixth line of text</span>
<span>seventh line of text</span>

I want to strip out the ul and li, and replace the li by span tags, is this possible?

3
  • you need to change the format only li to span? Commented Dec 15, 2015 at 14:00
  • 1
    Start by finding the block of code that creates $lines Commented Dec 15, 2015 at 14:00
  • Its using concrete5 so the core controllers i think creates the var based from the db.xml file but yes just want to change the outputted li to spans and remove the UL as well. the markup of the list it actually in the database so need to change from the output i guess. Commented Dec 15, 2015 at 14:01

1 Answer 1

3

Quick and dirty:

$lines = str_replace("<ul>", "", $lines);
$lines = str_replace("</ul>", "", $lines);
$lines = str_replace("<li>", "<span>", $lines);
$lines = str_replace("</li>", "</span>", $lines);

or shorter:

$array = array("<ul>", "</ul>", "<li>", "</li>");
$replace = array("", "", "<span>", "</span>");
$lines = str_replace($array, $replace, $lines);
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks mate, ill give it a quick go and let you know
Just integrating, getting a mysql error coming back so just sorting. Had to get an inline editor form finished but its all done, just not saving so sorting that and can then confirm :)
I don't get what you are trying to say :D So did this work or do you need more help? So describe your probleme.
Im getting a mysql error when saving the form so cannot get it saved to the database the ul list from the editor so then see the output yet - can you spot what its doing? i cannot see why getting the error: pastebin.com/aVWJfNfK
Accepted, im sure will work but will give you a shout if a problem - thanks for all your help mate.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.