Php trim function in middle clause

Asked
Active3 hr before
Viewed126 times

7 Answers

function
90%

Yeah PHP has got a whole whack of good string handling functions to use. php.net/manual/en/ref.strings.php Read a bit through the documentation and you'll find some really great ones – Etienne Marais Oct 14 '10 at 7:57 , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Making statements based on opinion; back them up with references or personal experience., By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

You can use str_replace:

$output = str_replace(' ', '', $input);
88%

The following MySQL statement returns the string after removing the leading and trailing spaces from the given string ' trim '.,The following MySQL statement returns the string after removing the leading string 'leading' from the given string 'leadingtext'.,The following MySQL statement returns the string after removing the trailing string 'trailing' from the given string 'texttrailing'.,The following MySQL statement returns the string after removing the leading and trailing string 'leadtrail' from the given string 'leadtrailtextleadtrail'.

Syntax:

TRIM([{
   BOTH | LEADING | TRAILING
} [remstr] FROM] str)
SELECT TRIM(' trim ');

Sample Output:

mysql > SELECT TRIM(' trim '); +
-- -- -- -- -- -- -- -- +
|
TRIM(' trim ') |
   + -- -- -- -- -- -- -- -- +
   |
   trim |
   + -- -- -- -- -- -- -- -- +
   1 row in set(0.00 sec)

Code:

SELECT TRIM(LEADING 'leading'
   FROM 'leadingtext');

Sample Output:

mysql > SELECT TRIM(LEADING 'leading'
   FROM 'leadingtext'); +
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +
|
TRIM(LEADING 'leading'
      FROM 'leadingtext') |
   + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +
   |
   text |
   + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +
   1 row in set(0.02 sec)

Code:

SELECT TRIM(TRAILING 'trailing'
   FROM 'texttrailing');

Sample Output:

 mysql > SELECT TRIM(TRAILING 'trailing'
    FROM 'texttrailing'); +
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
 |
 TRIM(TRAILING 'trailing'
       FROM 'texttrailing') |
    + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
    |
    text |
    + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
    1 row in set(0.00 sec)

Code:

SELECT TRIM(BOTH 'leadtrail'
   FROM 'leadtrailtextleadtrail');

Sample Output:

mysql > SELECT TRIM(BOTH 'leadtrail'
   FROM 'leadtrailtextleadtrail'); +
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
|
TRIM(BOTH 'leadtrail'
      FROM 'leadtrailtextleadtrail') |
   + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
   |
   text |
   + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
   1 row in set(0.00 sec)
load more v
72%

This function returns a string with whitespace stripped from the beginning and end of string. Without the second parameter, trim() will strip these characters: ,trim — Strip whitespace (or other characters) from the beginning and end of a string,ltrim() - Strip whitespace (or other characters) from the beginning of a string,rtrim() - Strip whitespace (or other characters) from the end of a string

string(32)
"        These are a few words :) ...  "
string(16)
"    Example string
"
string(11)
"Hello World"

string(28)
"These are a few words :) ..."
string(24)
"These are a few words :)"
string(5)
"o Wor"
string(9)
"ello Worl"
string(14)
"Example string"
load more v
65%

String functionsare used to perform an operation on input string and return an output string.Following are the string functions defined in SQL:,ASCII(): This function is used to find the ASCII value of a character.Syntax: SELECT ascii('t'); Output: 116Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.,REPEAT(): This function is used to write the given string again and again till the number of times mentioned.Syntax: SELECT REPEAT('geeks', 2); Output: geeksgeeks,SUBSTRING(): This function is used to find an alphabet from the mentioned size and the given string.Syntax: SELECT SUBSTRING('GeeksForGeeks.org', 9, 1); Output: ‘G’

ASCII():
Syntax: SELECT ascii('t');
Output: 116
load more v
75%

The syntax for the TRIM function in Oracle/PLSQL is:,If you do not choose a value for the first parameter (LEADING, TRAILING, BOTH), the TRIM function will remove trim_character from both the front and end of string1.,The Oracle/PLSQL TRIM function removes all specified characters either from the beginning or the end of a string.,The TRIM function can be used in the following versions of Oracle/PLSQL:

The syntax for the TRIM function in Oracle/PLSQL is:

TRIM([
   [LEADING | TRAILING | BOTH] trim_character FROM
] string1)
load more v
40%

By default, CHAR() returns a binary string. To produce a string in a given character set, use the optional USING clause: , REVERSE(str) Returns the string str with the order of the characters reversed. mysql> SELECT REVERSE('abc'); -> 'cba' This function is multibyte safe. , SPACE(N) Returns a string consisting of N space characters. mysql> SELECT SPACE(6); -> ' ', AS clause: Optional; cast the input string to a given type and length.

Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL. ASCII() works for 8-bit characters.

mysql > SELECT ASCII('2'); -
> 50
mysql > SELECT ASCII(2); -
> 50
mysql > SELECT ASCII('dx'); -
> 100
load more v
22%

/* Removes whitespace from beginning and end of a string if
 * the second parameter is omitted
 * First parameter must be the string
 * Second parameter is optional and can include an alternative character or set of characters.
 */

// Example 1
$string = " Hello world ";
$trimmedString = trim($string);
// Output = 'Hello world',

// Example 2
$string = "babcabcHello worldabbaca";
$trimmedString = trim($string, 'abc');
// Output = 'Hello world',
load more v

Other "function-undefined" queries related to "Php trim function in middle clause"