I'm extracting twitter user's profile image through JSON. For this my code is:
$x->profile_image_url
that returns the url of the profile image. The format of the url may be "..xyz_normal.jpg"
or "..xyz_normal.png"
or "..xyz_normal.jpeg"
or "..xyz_normal.gif"
etc.
Now I want to delete the "_normal" part from every url that I receive. How can I achieve this in php? I'm tired of trying it. Please help.
asked Aug 18, 2012 at 9:02
2
Php str_replace.
str_replace['_normal', '', $var]
What this does is to replace '_normal' with '' [nothing] in the variable $var. Or take a look at preg_replace if you need the power of regular expressions.
answered Aug 18, 2012 at 9:04
MatsemannMatsemann
20.2k18 gold badges57 silver badges88 bronze badges
3
The str_ireplace[] function does the same job but ignoring the case
like the following
output : Hello Peter!
for more example you can see
answered Feb 2, 2020 at 8:07
Irshad BabarIrshad Babar
1,20318 silver badges26 bronze badges
The str_replace[] function replaces some characters with some other characters in a string.
try something like this:
$x->str_replace["_normal","",$x]
answered Aug 18, 2012 at 9:11
Samy S.RathoreSamy S.Rathore
1,7853 gold badges25 silver badges43 bronze badges
$s = 'Posted On jan 3rd By Some Dude';
echo strstr[$s, 'By', true];
This is to remove particular string from a string.
The result will be like this
'Posted On jan 3rd'
answered Jan 3, 2018 at 7:03
chrischris
1916 bronze badges
Multi replace
$a = array['one','two','three'];
$var = "one_1 two_2 three_3";
str_replace[$a, '',$var];
answered Dec 25, 2019 at 3:09
string erase[subscript, count]
{
string place="New York";
place erase[0,2]
}
answered Sep 2, 2014 at 7:47
Not the answer you're looking for? Browse other questions tagged php string or ask your own question.
❮ PHP String Reference
Example
Remove characters from the right end of a string:
Try it Yourself »
Definition and Usage
The chop[] function removes whitespaces or other predefined characters from the right end of a string.
Syntax
Parameter Values
string | Required. Specifies the string to check |
charlist | Optional. Specifies which characters to remove from the string. The following characters are removed if the charlist parameter is empty:
|
Technical Details
Returns the modified string |
4+ |
The charlist parameter was added in PHP 4.1.0 |
More Examples
Example
Remove newlines [\n] from the right end of a string:
The HTML output of the code above will be [View Source]:
Hello World!
Hello World!
The browser output of the code above will be:
Hello World! Hello World!
Try it Yourself »
❮ PHP String Reference