gpt4 book ai didi

php - 使用php获取字符串的一部分

转载 作者:行者123 更新时间:2023-12-05 09:00:05 26 4
gpt4 key购买 nike

如何使用PHP获取字符串的一部分?

我有一个这样的字符串。

$str = 'href="http://www.idontknow.com/areyousure?answer=yes"';

我只想要链接......像这样

$str_new = "http://www.idontknow.com/areyousure?answer=yes";

最佳答案

$str_new = substr($str, 6, -1);

substr()

If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string).

If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes the position of this truncation or beyond, false will be returned.

If length is given and is 0, FALSE or NULL an empty string will be returned.

If length is omitted, the substring starting from start until the end of the string will be returned.

关于php - 使用php获取字符串的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6814930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com