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

如何使用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.

https://stackoverflow.com/questions/6814930/

相关文章:

asp.net - CS0433 : The type 'CrystalDecisions.Web.

asp.net - 有什么简单的方法可以检查复选框列表控件中是否没有选择任何项目?

css - float : left; Not working in IE?

ruby-on-rails - bcrypt 解密器

php - 需要 return ($a > $b) 的解释吗? -1 : 1 in php

jquery - 你如何使用 jquery 将一个下拉列表的选项复制到另一个下拉列表

iphone - UITableView 中图像的圆角矩形/圆角

sql-server - 用于生成序列号的 SQL Server 函数

qt - 如何解决(不兼容的发送方/接收方参数)问题?

java - 为什么我们不能将实例变量传递给父类(super class)构造函数?