Jump to content

How can i divide thisString?


sangoku

Recommended Posts

Ye right make a hell of a  server load to.... i can fetch a string to.... before arrays there were strings  ;D ... what was before string... int?  :-\

 

preg_filter — Perform a regular expression search and replace

preg_grep — Return array entries that match the pattern

preg_last_error — Returns the error code of the last PCRE regex execution

preg_match_all — Perform a global regular expression match

preg_match — Perform a regular expression match

preg_quote — Quote regular expression characters

preg_replace_callback — Perform a regular expression search and replace using a callback

preg_replace — Perform a regular expression search and replace

preg_split — Split string by a regular expression

 

 

which one and how to use it???  i think it is sine of thouse ,,, just have to figure how to use it....

Link to comment
Share on other sites

premiso was trying to steer you right with str_split.. it's afterwards that you'd use regex.. (the preg functions)

$aWord = str_split("SomeThing");
foreach($aWord as $letter) 
echo preg_match("#[A-Z]#", $letter) ? "It's uppercase!" : "It's lowercase!";

Link to comment
Share on other sites

i wrote this

 


function breakAt(array $positions, $str)
{
$prev = 0; foreach ($positions as $pos)
{
	$arr[] = substr($str, $prev, $pos-$prev);
	$prev  = $pos;
}
$arr[] = substr($str, $pos);
return $arr;
}

function str_splitByPreg($pattern, $str)
{
foreach (str_split($str,1) as $pos => $char) if (preg_match($pattern, $char)>0) $brkPos[$pos] = $pos;
return (empty($brkPos)) ? array($str) : breakAt($brkPos, $str);
}

function str_splitBy($byFunc, $str)
{
foreach (str_split($str,1) as $pos => $char) if ($byFunc($char)) $brkPos[$pos] = $pos;
return (empty($brkPos)) ? array($str) : breakAt($brkPos, $str);
}


function isLowerCase($char)
{
if ( (ord($char) > 96) && (ord($char) < 123) ) return TRUE;
return FALSE;
}


print_r(str_splitBy('isLowerCase', $str));

print_r(str_splitByPreg('/[a-z]/', $str));

 

 

Link to comment
Share on other sites

Those should suffice nicely to your task in hand. If you're worring about the server load it takes to split a string, Think roughly 172+92 bytes for **ZVALs on ZEND's engine + C's overhead, And in today's memory? It wouldn't take much load at all on anything under 1M+ len.

 

EDIT: Salathe, back off :-\

Link to comment
Share on other sites

sangoku, can you describe more thoroughly what you want? The details are important for offering a solution. If the aim is to "explode" into an array, you could use one way; to "explode" into a space-separated string you would use a different way. So, please describe as best you can  what you want to get from the string.

 

[ot]Edit: I hadn't even posted before oni-kun edited with "Salathe, back off  :-\" I wasn't going to comment on oni-kun's post anyway![/ot]

Link to comment
Share on other sites

X-D Ok i done it  but it dous not do what i want it to found some function on other forum which works for me

 



function humanize( $input )
{
    $input = preg_replace( '/([^A-Z])([A-Z][a-z]+)/U', '$1 $2', $input );
    $input = preg_split( '/\s+/', $input, -1, PREG_SPLIT_NO_EMPTY );
    $input = implode( ' ', $input );
   // $input = strtolower( $input );
    return $input;
}  


$string = 'Test testTest TesT.test test/test [test]test test(test)';

$string = humanize( $string );

echo $string;
//if should output : Test testTest TesT test test test [test] test test (test)
//but it outputs  Test testTest TesT.test test/test test[test] test test(test)

 

Ok how can i bypass the est/test test[test] test test(test) part the . is not important i take it out before this  XD

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.