Akib67 Akib67 - 3 months ago 6
CSS Question

How to do text formatting in php

I want to do text formatting italic of my data which is echo from database. In my database, synonyms field their are more than one name and I retrieve all in one echo. For example Calappa nucifera (L.) Kuntze , Cocos indica Royle are store in my db. For this rezone i replace ',' with 'new line'and then echo. I want to show:

Calappa nucifera (L.) Kuntze

Cocos indica Royle

But my code shows:

Calappa nucifera (L.) Kuntze

Cocos indica Royle

My code is below:

echo '<div style = "margin-left: 150px;">'.str_replace(',','<br />',$row["synonyms"]).'</div>';

Answer

If you are using inline style in your code you have bold only and not italic

then obtain the firts two word and in a proper span tag ad font-style:italic;

$mySino = explode( ','),  $row["synonyms"]);

echo '<div style = "margin-left: 150px;">' ;
foreach ($mySino as $key => $myRow) {  

  $myValue= explode( ' ', $myRow,  3);

    echo  '<span style="font-style: italic;">' . 
           (isset($myValue[0]) ? $myValue[0] : '') .
       ' ' . (isset($myValue[1]) ? $myValue[1] : '' ) .
      '</span> ' .( isset($myValue[2]) ? $myValue[2] : '') . '<br />';
}

echo     '</div>'  ;