HTML JSON form submission

JSON is commonly used as an exchange format between Web client and backend services. Enabling HTML forms to submit JSON directly simplifies implementation as it enables backend services to operate by accepting a single input format that is what’s more able to encode richer structure than other form encodings (where structure has traditional had to be emulated).

User agents that implement this specification will transmit JSON data from their forms whenever the form’s enctype attribute is set to application/json. During the transition period, user agents that do not support this encoding will fall back to using application/x-www-form-urlencoded. This can be detected on the server side, and the conversion algorithm described in this specification can be used to convert such data to JSON. lanjut…

Reversing a String by Word or Character

You want to reverse the words or the characters in a string.

Solution

Use strrev( ) to reverse by character:

print strrev(‘This is not a palindrome.’);
.emordnilap a ton si sihT

To reverse by words, explode the string by word boundary, reverse the words, then rejoin:

$s = “Once upon a time there was a turtle.”;
// break the string up into words
$words = explode(‘ ‘,$s);
// reverse the array of words
$words = array_reverse($words);
// rebuild the string
$s = join(‘ ‘,$words);
print $s;
turtle. a was there time a upon Once

Discussion

Reversing a string by words can also be done all in one line:
$reversed_s = join(‘ ‘,array_reverse(explode(‘ ‘,$s)));

#php Cookbook#