Jump to content

Recommended Posts

You do not understand what trim does.  Perhaps you should re-read the description of the function where it says: 

 

Strip whitespace (or other characters) from the beginning and end of a string

 

Notice the emphasis I've added to 2 words in that description.

Link to comment
https://forums.phpfreaks.com/topic/235874-help-me/#findComment-1213229
Share on other sites

Have you seen the example given on php manual website which is as follows:

<?php

$text   = "\t\tThese are a few words  ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);

print "\n";

$trimmed = trim($text);
var_dump($trimmed);

$trimmed = trim($text, " \t.");
var_dump($trimmed);

$trimmed = trim($hello, "Hdle");
var_dump($trimmed);

// trim the ASCII control characters at the beginning and end of $binary
// (from 0 to 31 inclusive)
$clean = trim($binary, "\x00..\x1F");
var_dump($clean);

?>

 

The last trim gives correct result but when I change it to

$trimmed = trim($hello, "HdWr");
var_dump($trimmed);

it doesnot strip off W.

I am attachoing the code here with.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/235874-help-me/#findComment-1213253
Share on other sites

You do not understand what trim does.  Perhaps you should re-read the description of the function where it says: 

 

Strip whitespace (or other characters) from the beginning and end of a string

 

Notice the emphasis I've added to 2 words in that description.

 

It really says:

This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters:

The description is

string trim ( string $str [, string $charlist ] )

And the explaination of the $charlist is:

Optionally, the stripped characters can also be specified using the charlist parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.

 

So it should remove everything you add to the $charlist and it does for somethings. Very intermittent on output.

Link to comment
https://forums.phpfreaks.com/topic/235874-help-me/#findComment-1213388
Share on other sites

Sunfighter, if you don't have anything meaningful to add, please don't post.  Not only is what you posted nonsense, it actually suggests that the function doesn't work as described which it most certainly does. 

 

It is not a search and replace function, it only removes things from the beginning and end of a string.  If the characters in the list are at the beginning or end of the tring it will remove them, if not then it doesn't.  This is clear from the examples. 

 

 

Link to comment
https://forums.phpfreaks.com/topic/235874-help-me/#findComment-1213444
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.