PHP Count comma separated items
Moderator: General Moderators
PHP Count comma separated items
Hi everyone,
I have a column of data in mysql (email attachments) listed like so:
042208-FK/doc67834968.pdf[doc67834968.pdf],doc678349689.pdf[doc678349689.pdf]
is there a way in php to strip off everything prior to and including the forward slash and then count the filenames? In the example above, the count would be 2.
I'm not quite sure how to accomplish that. If anyone has any helpful hints, I'd appreciate it. Thanks.
I have a column of data in mysql (email attachments) listed like so:
042208-FK/doc67834968.pdf[doc67834968.pdf],doc678349689.pdf[doc678349689.pdf]
is there a way in php to strip off everything prior to and including the forward slash and then count the filenames? In the example above, the count would be 2.
I'm not quite sure how to accomplish that. If anyone has any helpful hints, I'd appreciate it. Thanks.
Re: PHP Count comma separated items
like so?
$string = $result['Attachments'];
$array = explode(',', $string);
$Attachments = count($array);
$string = $result['Attachments'];
$array = explode(',', $string);
$Attachments = count($array);
Re: PHP Count comma separated items
You tell me. Is that not working?
Re: PHP Count comma separated items
not quite. it indicates 0, but there are 2 files in the $result['Attachments']
Re: PHP Count comma separated items
Code: Select all
$string = '042208-FK/doc67834968.pdf[doc67834968.pdf],doc678349689.pdf[doc678349689.pdf]';
$array = explode(',', $string);
$count = count($array);
var_dump($count);Re: PHP Count comma separated items
Yes I have.
I've checked the value in the db and echoed $result['Attachments'] field to the screen, and I do get: 042208-FK/doc67834968.pdf[doc67834968.pdf],doc678349689.pdf[doc678349689.pdf], it's just not displaying the count.
I've checked the value in the db and echoed $result['Attachments'] field to the screen, and I do get: 042208-FK/doc67834968.pdf[doc67834968.pdf],doc678349689.pdf[doc678349689.pdf], it's just not displaying the count.
Re: PHP Count comma separated items
Doesn't make much sense that it should work for me and not for you. What about after count()?
Code: Select all
var_dump($result['Attachments']); var_dump($array);Re: PHP Count comma separated items
I figured out where I went wrong. Yes the count works just fine now. Thanks.