If I had:
$string = "PascalCase";
I need
"pascal_case"
Does PHP offer a function for this purpose?
If I had:
$string = "PascalCase";
I need
"pascal_case"
Does PHP offer a function for this purpose?
A regex would be simplest:
$input = 'foo_left.jpg';
if(!preg_match('/_(left|right|center)/', $input, $matches)) {
// no match
}
$pos = $matches[0]; // "_left", "_right" or "_center"
See it in action.
Update:
For a more defensive-minded approach (if there might be multiple instances of "_left"
and
friends in the filename), you can consider adding to the regex.
This will match only if the l/r/c is followed by a dot:
preg_match('/(_(left|right|center))./', $input, $matches);
This will match only if the l/r/c is followed by the last dot in the filename (which practically means that the base name ends with the l/r/c specification):
preg_match('/(_(left|right|center))\.[^\.]*$/', $input, $matches);
And so on.
If using these regexes, you will find the result in $matches[1]
instead of $matches[0]
.
The following works invoke it as select * from table(splitter('a,b,c,d'))
create or replace function splitter(p_str in varchar2) return sys.odcivarchar2list
is
v_tab sys.odcivarchar2list:=new sys.odcivarchar2list();
begin
with cte as (select level ind from dual
connect by
level <=regexp_count(p_str,',') +1
)
select regexp_substr(p_str,'[^,]+',1,ind)
bulk collect into v_tab
from cte;
return v_tab;
end;
/
Use String.Format() with the format specifier. I think you want {0:F20} or so.
string formatted = String.Format("{0:F20}", value);
This can't work properly. Stored with Unicode there are many more Characters than with ANSI. So if you "convert" to ANSI, you will loose lots of charackters.
http://php.net/manual/en/function.htmlentities.php
You can use Unicode (UTF-8) charset with htmlentities:
string htmlentities ( string $string [, int $flags = ENT_COMPAT [, string $charset [, bool $double_encode = true ]]] )
htmlentities($myString, ENT_COMPAT, "UTF-8");
should work.
Try this on for size:
Output:
This implements the following rules: