Php instance: Reverse string by word or byte

Source: Internet
Author: User
Problem: You want to reverse the word or byte order of a string. scheme: reverse by byte: strrev () function reverse by word: you can break down the entire string into independent characters based on the space characters between words, reverse the order of these words, and re-combine the reversed words. Explode () function array_reverse () function implode function

Question: You want to reverse the character or byte order of a string.
Scheme: Byte reversal: the strrev () function reverses by word: you can first split the entire string into independent words based on the space characters between words, and then reverse the order of these words, finally, the reversed words are combined. Explode () function array_reverse () function implode function

 

$s='my blog lostphp';echo strrev($s).'';$word=explode(' ',$s);$word=array_reverse($word);$s=implode(' ',$word);echo $s;
Summary: array explode (string $ separator, string $ string [, int $ limit]) This function returns an array composed of strings, each element is a string substring, they are separated by the string separator as the boundary points. If the limit parameter is set, the returned array contains up to limit elements, and the last element contains the rest of the string.

If separator is a null string (""), explode () returns FALSE. If the value of separator cannot be found in string, explode () returns an array containing a single string element.

If the limit parameter is negative, all elements except the last-limit element are returned.



Array array_reverse (array $ array [, bool $ preserve_keys]) accepts array as input and returns a new array in reverse order. if preserve_keys is TRUE, the original key name is retained.





 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.