Jump to content

Trim() not working on development server


ste1986

Recommended Posts

Hi,

 

I've got a very weird problem! I'm writing a script that will manipulate some pasted text... most of the code uses trim() to clear characters/words from the beginnings of lines. It doesn't work on it's own trim($string) or with the seperate argument trim($string , "text").

 

The code is fine, it works ok one of our paid for hosting servers (pre-configured), but it won't work on either of our dev servers! All are using Apache. Version info:

Hosting Server (Linux - works)... PHP 4.4.6

Dev 1 (Linux - doesnt work)... PHP 4.3.9

Dev 2 (Windows doesnt work)... PHP 5.2.1

 

It's stumped me! I always assumed that something as simple as trim() would be enabled by default. Can anyone shed any light?

Link to comment
https://forums.phpfreaks.com/topic/44473-trim-not-working-on-development-server/
Share on other sites

If you are facing a prb because of a version then try this code

 

function trim_str($str){

if(strlen($str) > 0){

$str = preg_replace("/^\s+/","",$str);

$str = preg_replace("/\s+$/","",$str);

return $str;

}

return $str;

}

echo "This is trimed string".trim_str('  test  ');

No errors at all, just not changing the output... Sloppy code so don't laugh :P

 

$text1 = "Loads of view
multi line
code etc
etc etc
etc etc"
$text2 = strtok("$text1" , "\n");

$count = 1;
while($count <= 10) {
Print($text2 . "<BR>");
/* $list1 = $list1 . "'" . $text2 . "', "; */
$array1[$count] = $text2;
$text2 = strtok("\n");
$count = $count + 1;
}
$result1 = $array1[1];
$result1 = rtrim($result1, "view");

Print($result1."<br>");
Print($array1[2]."<br>");
Print($array1[3] ."<br>");
Print($array1[4] ."<br>");
Print($array1[5] ."<br>");
Print($array1[6] ."<br>");
Print($array1[7] ."<br>");
Print($array1[8] ."<br>");
Print($array1[9] ."<br>");
Print($array1[10] ."<br>");

 

So in that one, I just want it to trim the word view from the first line, but it doesnt do it on my dev servers...

Panic over! Sorry to waste your time guys... it looks like it was either a problem with my code or the text I was pasting in!

 

I changed it to:

$result1 = trim($result1);
$result1 = trim($result1, "view");
$result1 = trim($result1);

 

It now works fine... weird that it worked ok on the other server though! Must just be a random setting. I'll post back if I figure out what the setting is! Thanks again  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.