Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 如何遇到某字元就截取?

如何遇到某字元就截取?

Jun 23, 2016 pm 01:54 PM
intercept

比如经常发表一些新闻

格式都是很规则的使用  XXXXXXX, XXX。XXXXXX,XXXXX。

如何做到,  截取第一次出现的。及之前的文字
或第二次出现。及之前前文字

比如以下红字

这里发言,表示您接受了CSDN论坛的用户行为准则。请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。


如何用php来智能截取?  第一或第二句  一个"。"算一句


回复讨论(解决方案)

$s = '这里发言,表示您接受了CSDN论坛的用户行为准则。请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。';echo preg_replace('/((?:.+?。){1}).+/', '$1', $s);
Copy after login
这里发言,表示您接受了CSDN论坛的用户行为准则。
echo preg_replace('/((?:.+?。){2}).+/', '$1', $s);
Copy after login
这里发言,表示您接受了CSDN论坛的用户行为准则。请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。

用explode 以。号分割也是可以的

谢谢两位版主

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of string interception method in Go language Detailed explanation of string interception method in Go language Mar 13, 2024 am 08:03 AM

Detailed explanation of string interception methods in Go language. In Go language, strings are immutable byte sequences, so some methods need to be used to implement string interception. String interception is a common operation to obtain a specific part of a string. You can intercept the first few characters, the last few characters of the string, or a certain length of characters from a specific position according to your needs. This article will introduce in detail how to intercept strings in Go language and provide specific code examples. Using slicing to implement string interception In Go language, you can use slicing to

How to use ROUND function to intercept decimal places in MySQL How to use ROUND function to intercept decimal places in MySQL Jul 13, 2023 pm 09:21 PM

How to use the ROUND function in MySQL to intercept the number of decimal places. In MySQL, you can use the ROUND function to intercept the number of decimal places. The ROUND function rounds a number to a specified number of decimal places. The following will introduce you to the use of ROUND function in detail and provide code examples. Syntax: ROUND(X,D)X represents the number to be rounded, and D represents the number of decimal places to be retained. Example of using the ROUND function to intercept the number of decimal places: Suppose there is a table named produc

PHP Chinese string interception skills: Say goodbye to mb_substr() PHP Chinese string interception skills: Say goodbye to mb_substr() Mar 15, 2024 pm 12:18 PM

In PHP development, we often encounter situations where Chinese strings need to be intercepted. Traditionally, we usually use the mb_substr() function to handle the interception of Chinese characters, but its performance is poor and not readable enough. This article will introduce some new Chinese string interception techniques, let us say goodbye to mb_substr(), and improve code efficiency and readability. Use regular expressions to intercept Chinese strings. Using regular expressions to intercept Chinese strings is an efficient and concise method. We can match Chinese characters through regular expressions

Quickly master the string interception function in Go language Quickly master the string interception function in Go language Mar 12, 2024 pm 06:15 PM

Quickly master the string interception function in Go language. Go language is a programming language that has attracted much attention in recent years. It has the characteristics of simplicity and efficiency, and is favored by more and more developers. In the Go language, string processing is a very common operation, and the string interception function is an important part of it. This article will use specific code examples to help you quickly master the string interception function in Go language. 1. Basic string interception. Strings in Go language can be intercepted through index. The code example is as follows: package

How UniApp implements image uploading and cropping How UniApp implements image uploading and cropping Jul 06, 2023 am 10:01 AM

UniApp is a cross-platform application development framework based on Vue.js, which can quickly develop applications for both iOS and Android platforms. In UniApp, uploading and cropping images is a common requirement. This article will introduce how to implement image uploading and cropping in UniApp, and provide corresponding code examples. 1. How to implement image upload: Use the uni.uploadFile() method to upload images. First, you need to configure uni.uploa

How to optimize string interception and splicing performance in Java development How to optimize string interception and splicing performance in Java development Jun 29, 2023 pm 06:04 PM

How to optimize the performance of string interception and splicing in Java development. In daily Java development, string interception and splicing are very common operations. However, due to the immutable nature of strings in Java, frequent string interception and splicing operations may cause performance degradation. In order to improve the performance of string interception and splicing in Java development, we can adopt the following optimization strategies. Concatenation using StringBuilder or StringBuffer: In Java, String

In-depth understanding of the implementation principle of string interception in Go language In-depth understanding of the implementation principle of string interception in Go language Mar 12, 2024 pm 06:27 PM

As a high-performance programming language, Go language provides a wealth of methods and functions for string operations and processing. Among them, string interception operation is one of the functions we often use. In this article, we will delve into the implementation principle of string interception in Go language and demonstrate the implementation process through specific code examples. What is string interception? In Go language, string interception refers to the operation of intercepting partial substrings from a string. By specifying the starting position and ending position, we can obtain the specified range in the original string

New features in Java 12: How to use the new String API to intercept and concatenate strings New features in Java 12: How to use the new String API to intercept and concatenate strings Jul 31, 2023 pm 12:55 PM

As a widely used programming language, Java has been continuously developed and updated. Each new version will introduce some new features and functions to improve developers' coding efficiency. One of the features of Java12 as the latest version is the introduction of the new StringAPI, which makes string interception and concatenation more convenient and efficient. In previous versions, string interception and concatenation operations needed to be implemented by calling substring() and the "+" operator, but these methods were unable to handle a large number of string operations.

See all articles