How to solve string operations

Source: Internet
Author: User
Tags getting started with php
The string operation has a variable: $ arr [0] 1. I want to determine the length of the variable, which contains several characters. how can I do this? 2. what should I do if I want to take two places on the left? Just getting started with PHP, please teach me ------ solution ------------------ $ nstrlen ($ arr [0]); $ msubstr ($ arr [0],); ------ solution ---------- string operation
There is a variable: $ arr [0]
1. how can I determine the length of a string containing several characters?
2. what should I do if I want to take two places on the left?

I just got in touch with PHP. please teach me

------ Solution --------------------
$ N = strlen ($ arr [0]);
$ M = substr ($ arr [0], 0, 2 );
------ Solution --------------------

Int strlen (string)
Get the string length, strlen (your string)

String substr (string, int start [, int length])
Substr (your string, 0, 2 );
------ Solution --------------------
$ Len = strlen ($ arr [0]);
$ Str = substr ($ arr [0], 0, 2 );


------ Solution --------------------
Pay attention to whether the string contains wide characters.
------ Solution --------------------
The width is unicode.

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.