سؤال

I got a line of code in the project i'm trying to modify/add extension to.

$controller = 'Controller' . preg_replace('/[^a-zZ-Z0-9]/', NULL, $action['class']);

but i'm not sure if this line dose what i think it dose: Capitalize the first letter, i.e. turn "order" into "Order"

i tried a few tests, but it doesn't make any sense, as it seems to remove capital letters in words..

هل كانت مفيدة؟

المحلول

This will simply remove the first alphanumeric character in $action['class'].

If you want to uppercase the first letter, use ucfirst:

$action['class'] = ucfirst($action['class']);

نصائح أخرى

You might want to use ucfirst(). It will capitalize the first character of a string.

This doesn't seem to make a lot of sense and looks like a typo. In its current form, it replaces everything, that is not a-z, Z, 0-9 with NULL. I assume, what was really meant, is this:

'/[^a-zA-Z0-9]/'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top