-3
$A=123132,32132,123132321321,3
$B=1,32,99
$C=456,98,89
$D=1

I want to cut string after first comma

output. . .

$A=123132
$B=1
$C=456
$D=1
rizzz86
  • 3,862
  • 8
  • 35
  • 52

4 Answers4

1

You can do this with strpos to get the position of the first comma, and substr to get the value prior to it:

<?php

    $val='123132,32132,123132321321,3';
    $a=substr($val,0,strpos($val,','));

    echo $a;

?>

Output:

123132

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
1

$newA = current(explode(",", $A));

from: PHP substring extraction. Get the string before the first '/' or the whole string

Community
  • 1
  • 1
Kinnectus
  • 899
  • 6
  • 14
0

There are a number of ways to accomplish this:

substr($A,0,strpos($A,","))

or

current(explode(",", $A))

will both return the value 123132

mifi79
  • 1,086
  • 6
  • 8
-1

You can do

$A='123132,32132,123132321321,3';
$t=explode(',',$A);
$result = $t[0];
Michel
  • 4,076
  • 4
  • 34
  • 52