trim() / ltrim()
Posted: Tue Jul 22, 2003 7:18 am
I'm having a strange problem. I've made a script that turns a load of URLS submitted into a form as text into clickable links.
Included with this script is a feature which checks if the links are active or not with the use of fopen().
My problem is that as the links are extracted from the text, using the explode() function, separated by semi-colons, whitespace is left at the front of each resultant string, meaning that fopen() always fails due to the leading whitespace.
I have tried trim()ing and ltrim()ing each URL string, however it fails at stripping any leading whitespace.
I made another example to check my ltrim() useage, and still it doesn't want to strip the unwanted whitespace.
If $text is entered into the above string with leading spaces, it doesn't strip the spaces/whitespace at all... 
The PHP manual says that without using the 2nd paramater for the ltrim() function, it strips whitespace, new rows, tabs and all... however I just can't get it to work?
If anyone could shed any light on this problem I would be really grateful...
Included with this script is a feature which checks if the links are active or not with the use of fopen().
My problem is that as the links are extracted from the text, using the explode() function, separated by semi-colons, whitespace is left at the front of each resultant string, meaning that fopen() always fails due to the leading whitespace.
I have tried trim()ing and ltrim()ing each URL string, however it fails at stripping any leading whitespace.
I made another example to check my ltrim() useage, and still it doesn't want to strip the unwanted whitespace.
Code: Select all
<?php
if(!empty($_POST[text])) {
trim($_POST[text]);
echo '"'."$_POST[text]".'"';
}
?>The PHP manual says that without using the 2nd paramater for the ltrim() function, it strips whitespace, new rows, tabs and all... however I just can't get it to work?
If anyone could shed any light on this problem I would be really grateful...