qatorni qatordan o'zgartiradi

Hozir menda qator bor

$cop_row = array('first_pulse1', 'second_pulse2');

Men nima istaymanto replace first_ & second_ from the cop_row array .

Men hozir buni qo'llayman, lekin bu menga kerakli natijani bermaydi.

str_replace("first_","",$cop_row);

Men chiqdi

pulse1second_pulse2

Men nima istayman

pulse1pulse2

Tashvishingiz uchun tashakkur.

1

6 javoblar

bu sizning muammoingizni hal qiladi.

php > $x = ['first_pulse', 'second_pulse'];
php > $q = preg_replace('/(\w+)_/i', '', $x);
php > print_r($q);
Array
(
    [0] => pulse
    [1] => pulse
)
php > 

http://php.net/manual/en/function.preg-match. PHP

2
qo'shib qo'ydi
Ha, men buni va uning ishini sinab ko'rdim. Tnx
qo'shib qo'ydi muallif metalhead101, manba

Agar strings har doim bu kabi formatlangan bo'lsa, unda bu oddiy RegExp almashinuvidan foydalanishingiz mumkin:

preg_replace("/^.*_/", "", $cop_row)

Ushbu modelga ba'zi yaxshilanishlar kerak bo'lishi mumkin, ammo u sizning holatlaringiz uchun ishlaydi.

Agar siz naqsh bo'yicha qo'shimcha yordam yoki tushuntirish kerak bo'lsa, so'rang!

2
qo'shib qo'ydi
$cop_row = array('first_pulse1', 'second_pulse2');

foreach ($cop_row as $key => $value) {
    $result_array[] = substr($value, strpos($value, "_") + 1);  
}

print_r($result_array);

Working example here - http://codepad.org/nOqWdmNu

2
qo'shib qo'ydi
$cop_row = array('first_pulse1', 'second_pulse2');

foreach ($cop_row as $key => $value) {
    $result_array[] = substr($value, strpos($value, "_") + 1);  
}

print_r($result_array);

Working example here - http://codepad.org/nOqWdmNu

2
qo'shib qo'ydi

Buni ko'ring:

 $replace = ["first_","second_"];
 $cop_row = array('first_pulse1', 'second_pulse2');
 str_replace($replace,"",$cop_row);

Please have a look into https://www.w3schools.com/php/func_string_str_replace.asp

1
qo'shib qo'ydi

preg_replace dan foydalanishingiz mumkin.

$cop_row = array('first_pulse1', 'second_pulse2');

$patterns[0] = '/first_/';
$patterns[1] = '/second_/';
foreach($cop_row as $row){
    echo preg_replace($patterns, '', $row); 
}
1
qo'shib qo'ydi
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin