Question: How to get a part of string using PHP?

I have a string like this.

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

```

I want only the link.. like this

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

```

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

```

[`substr()`](http://php.net/function.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.
> 
> 
>
Use a regular expression:

```
$str = 'href="http://www.idontknow.com/areyousure?answer=yes"';
$string = preg_replace ( '/href="(.*)"/', '\1', $str );

```