Page 1 of 1

PHP split() function - Regular Expression "Reversal&quo

Posted: Tue Jan 18, 2005 7:44 am
by revof11
Hello everone. I have a little snippit of code here that does the opposite of what I need it to do and was hoping someone could offer some help.

Suppose you have the following text:

Code: Select all

I am some їrandom] text.  This is їsomething.something] that їbla] and їbla:bla].
This information is stored as a string in a variable in my php script. And I am using the following code:

Code: Select all

$isolatedData = split("\\ї(її:print:]]+)\\]", $contents);
When printing the contend of $isolatedData, the following appears:

Code: Select all

I am some
text.  This is
that
and
Basically, what I am trying to do is figure out the "opposite" of that to get the following:

Code: Select all

їrandom]
їsomething.something]
їbla]
їbla:bla]
I tried using the ereg function with the final array parameter in this fashion:

Code: Select all

ereg("\\ї(її:print:]]+)\\]", $contents, $isolatedData);
However, this only gives me back [random] andrandom,

Can anyone help out?
Thanks.

Posted: Tue Jan 18, 2005 8:29 am
by feyd
the ereg functions are .. slow. I suggest using preg_*

example

Code: Select all

preg_match_all('#\ї(.*?)\]#', $yourText, $matches);
print_r($matches);

Posted: Tue Jan 18, 2005 12:54 pm
by revof11
That worked perfectly!
Thank you!

I also didn't know about the overhead.
I'll keep that in mind.