Hướng dẫn replace first word php
how to find and replace the first word from the string using php eg:
expected result should be 'Super World Hello World' as it does not match with first word. eg2:
expected result should be 'Hi World Hello World' as it does match with first word. please help asked Mar 14, 2018 at 18:37
4 Create a function for this, passed 3 arguments. Logic is convert string into array by
Demo answered Mar 14, 2018 at 18:58
Bhaskar JainBhaskar Jain 1,6111 gold badge11 silver badges20 bronze badges 0 (PHP 4, PHP 5, PHP 7, PHP 8) substr_replace — Replace text within a portion of a string Descriptionsubstr_replace( Parametersstring The input string. An array of
strings can be provided, in which case the replacements will occur on each string in turn. In this case, the replace The replacement string. offset If If length If given and is positive, it represents the length of the portion of Return Values The result string is returned. If Changelog
ExamplesExample #1 Simple substr_replace() examples
Example #2 Using substr_replace() to replace multiple strings at once
The above example will output: A: YYY; B: YYY; C: YYY A: AAA; B: BBB; C: CCC A: AAAXX; B: BBBX; C: CCC Notes
See Also
elloromtz at gmail dot com ¶ 12 years ago
billg AT microsoft.com ¶ 13 years ago
$start < 0) eblejr AT phrebh DOT com ¶ 14 years ago
juichenieder-phnet at yahoo dot co dot uk ¶ 13 years ago
ivijan dot stefan at gmail dot com ¶ 8 years ago
danieldoorduin at hotmail dot com ¶ 17 years ago
Hayley Watson ¶ 5 years ago
Thijs Wijnmaalen (thijs[at]nllinux.nl) ¶ 18 years ago
strlen($text) > $maxChars) { William Barry ¶ 14 years ago
// Find the first closing ul kalim dot fleet at gmail dot com ¶ 12 years ago
= 'abcdefghijklmnopqrstuvwxyz0123456789z.jpg'; mrbrown8 at juno dot com ¶ 21 years ago
hermes at andycostell dot com ¶ 17 years ago
den dot gierling at web dot de ¶ 12 years ago
Guru Evi ¶ 17 years ago
klaas at group94 dot com ¶ 20 years ago
alishahnovin at hotmail dot com ¶ 15 years ago
shaman_master at list dot ru ¶ 2 years ago
bkline at rksystems dot com ¶ 3 years ago
meg dot phillips91 at gmail dot com ¶ 2 years ago
yeyijelud at amadamus dot com ¶ 3 years ago
NiX0n at fragfest dot cx ¶ 13 years ago
spcl dot delivery at gmail dot com ¶ 14 years ago
jaimthorn at yahoo dot com ¶ 14 years ago
chuayw2000 at hotmail dot com ¶ 16 years ago
david at ethinkn dot com ¶ 19 years ago
truncate ('akfhslakdhglksjdgh', 10, '...'); nospam at nospam dot com ¶ 6 years ago
strShorten('123456789', 6, ''); // outputs 123789 dmron ¶ 18 years ago
Anonymous ¶ 20 years ago
blessador at gmail dot com ¶ 9 years ago
at the end of substr_replace ($price, ',', -3, 0)" in the above code to avoid error.
geniusdex ( at ) brz ( dot ) nu ¶ 18 years ago
tony at outshine dot com ¶ 18 years ago
ntoniazzi at sqli dot com ¶ 14 years ago
thomasNOSPAM at sportentranceNOSPAM dot com ¶ 19 years ago
olav at schettler dot net ¶ 6 years ago
admiral at nuclearpixel dot com ¶ 12 years ago
admiralsTruncate($my_string, 6); // outputs: cfcd20echo ' |