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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
revof11
Forum Newbie
Posts: 16
Joined: Tue Jan 18, 2005 7:30 am
Location: Mountain Top, PA
Contact:

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the ereg functions are .. slow. I suggest using preg_*

example

Code: Select all

preg_match_all('#\ї(.*?)\]#', $yourText, $matches);
print_r($matches);
User avatar
revof11
Forum Newbie
Posts: 16
Joined: Tue Jan 18, 2005 7:30 am
Location: Mountain Top, PA
Contact:

Post by revof11 »

That worked perfectly!
Thank you!

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