user1721135
user1721135

Reputation: 7092

Whitespace in textarea

I build an array of URLs from the content of a textarea, than process it with simple php dom.

I get this error:

Warning: file_get_contents(http://www.example.com )

Obviously, there is a whitespace at the end of the URL (which is the last in the array and the last in the textarea)

I checked other questions on stackoverflow, but I still can not get rid of this whitespace and get my script to work, even though my textarea tag contains no whitespaces at all.

This is what my textarea looks like (no whitespace anywhere):

    <textarea id="textarea" name="textarea" value=""></textarea><br><br>

The array is separated by \n

I even make sure to delete possible whitespaces using the del key after the last entry in the textarea, but I keep getting the same error.

How can I fix this?

Upvotes: 0

Views: 115

Answers (1)

V13Axel
V13Axel

Reputation: 838

The PHP trim function will do what you need it to. Just change your file_get_contents($url) to file_get_contents(trim($url)) and it should never have that problem.

Upvotes: 2

Related Questions