Php string truncation problem! Online and other online stickers

Source: Internet
Author: User
Php string truncation problem! Paste yybb_cx online.
Yybb_xdf.

Just like the above string. I only need the letters behind _ and before.

For example, what I need are cx and xdf?


Reply to discussion (solution)

$ S = <
  
  

Does this replace the original one?



$ S = <
     
    

Eldest brother, I have never engaged in php.

In fact, what I want is very simple, that is

$ Datas = $ _ POST ["shujuku"]; // I have a sent string assigned to $ datas, which is like yybb_xdf.

Now I want to extract the $ datas string between _ and. according to my requirements and assign it to a new variable.

Preg_match ('/_ (. + ?) \./S', $ data, $ m); $ a = $ m [1]; // $ a is the variable you want

Preg_match ('/_ (. + ?) \./S', $ data, $ m); $ a = $ m [1]; // $ a is the variable you want


Eldest brother .. There is only one vertex...

I took the letters before and after. I now use your last variable $ a to marry only one.

No way. paste your code to see it.

If you don't like regular expressions, just intercept them.

$a = "yybb_cx.";$a = substr(substr($a,5),0,-1);echo $a;

No, No. I made a mistake. It shouldn't be before. You only need to underline the letter !!!!

$a = "yybb_cx.";$a = substr($a,5);echo $a;

$s = 'yybb_cx.';strtok($s, '_');$a = strtok('.');echo $a; //cx

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.