Php truncates a string between two characters.

Source: Internet
Author: User
Php intercepts a string between two characters. Php intercepts a string between two characters. This document describes how php intercepts a string between two characters. Share it with you for your reference. For example, php intercepts a string between two characters and intercepts a string.

This example describes how php intercepts a string between two characters. Share it with you for your reference. The details are as follows:

In php, you only need to determine a stripos location before String 1 and string 2, and then use substr to start the truncation. here is a simple example.

Usage:

$ Keyword = 'Search (group experiment) '$ need = getNeedBetween ($ keyword ,'(',')');

After running the program:

$ Need = 'group lab ';

The following describes how to use the string truncation function getNeedBetween. This function allows you to extract strings between two specified characters ($ mark1, $ mark2) from the string ($ kw). If the string fails, 0 is returned, and the string is successfully returned.

<?phpfunction getNeedBetween($kw1,$mark1,$mark2){$kw=$kw1;$kw='123′.$kw.'123′;$st =stripos($kw,$mark1);$ed =stripos($kw,$mark2);if(($st==false||$ed==false)||$st>=$ed)return 0;$kw=substr($kw,($st+1),($ed-$st-1));return $kw;}?>

I hope this article will help you with php programming.

Examples in this article describes how php intercepts strings between two specified characters. Share it with you for your reference. For details, see...

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.