Posts by wbraganca • 326 points
6 posts
-
3
votes3
answers4243
viewsA: How to check if return from Ajax is JSON or String?
Try using the following function: function isJson(str) { try { JSON.parse(str); } catch (e) { return false; } return true; } // exemplo de uso var str = '{' + '"tipo":1,' + '"usuario":"Guilherme",'…
-
1
votes1
answer350
viewsA: Recover Only Geocode City Name Maps PHP
Try this: <?php function geocode($lat, $long) { $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng={$lat},{$long}&sensor=false"; $content = @file_get_contents($url); $location =…
-
2
votes6
answers3209
viewsA: How to turn string into time in PHP?
Try the code below: <?php $string1 = strtotime("12:04:32"); $string2 = strtotime("18:07:34"); $intervalo = abs($string2 - $string1); var_dump('Diferença em segundos: ' . $intervalo); $minutos =…
-
2
votes1
answer1288
viewsA: HTML Special Character Encoder and Decoder
Try the code below: <?php function html_encode($content, $doubleEncode = true) { return htmlentities($content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode); } function…
-
5
votes2
answers1618
viewsA: Sort array by key, being a string
You need to sort the keys using the natural sorting algorithm. See the example below: <?php $dados = [ 'A1'=> 'A1', 'A10'=> 'A10', 'A11'=> 'A11', 'A12'=> 'A12', 'A2'=> 'A2',…
-
2
votes1
answer394
viewsA: Date format in PHP from SQL server
Change your query to the code below: SELECT CONVERT(VARCHAR(19), GETDATE(), 120) AS DATA As a result you’ll have something like: 2015-10-02 13:45:05…