March 6, 2013

convert date format within a webservice php context

Question by Peter van der Lely

I am consuming a webservice in php. The piece of code below gives me the following result with regard to the date notation:

Begindatum : 2012-07-02T00:00:00. I would like to have that in a European format like:

Begindatum : 02-07-2012. I’ve been trying to imlement the standard solution:

Convert date format yyyy-mm-dd => dd-mm-yyyy

but without succes. Help is appreceated.

 foreach($array as $k=>$v){
 print "
 <tr>
      <td>
            <ul>
                <li><b>Naam         : {$v->Naam}</b></li>
                <li><b>Status       : {$v->Status}</b></li>
                <li><b>Aanbieder    : {$v->VerstrekkerNaam}</b></li>
                <li><b>Bedrag       : {$v->Bedrag}</b></li>
                <li><b>Begindatum   : {$v->Begindatum}</b></li>

            </ul>
      </td>
</tr>

Answer by Starx

You can try this

$d = "2012-07-02T00:00:00";
echo $newDate = date("d-m-Y",strtotime($d));

Demo

In your code you may apply it as

foreach($array as $k=>$v){
 print "
 <tr>
      <td>
            <ul>
                <li><b>Naam         : {$v->Naam}</b></li>
                <li><b>Status       : {$v->Status}</b></li>
                <li><b>Aanbieder    : {$v->VerstrekkerNaam}</b></li>
                <li><b>Bedrag       : {$v->Bedrag}</b></li>
                <li><b>Begindatum   : {" . date("d-m-Y",strtotime($v->Begindatum)) ."}</b></li>
            </ul>
      </td>
</tr>
August 4, 2010

Text to HTML in PHP

Question by user409257

nl2br(); can do for EOL but what about white spaces and/or tabs at the beginning(or not) of line? Is there any function to do this at once? I need well formatted html output of text file.
Thx.

Answer by Starx

well may be <pre>....</pre> can do it

also see

htmlspecialchars()

http://php.net/manual/en/function.htmlspecialchars.php

htmlentities()

http://www.php.net/manual/en/function.htmlentities.php

...

Please fill the form - I will response as fast as I can!