/    Sign up×
Community /Pin to ProfileBookmark

Regexp / Explode help

Hi, I have a text file that’s list of Enlgish words, with their Arabic counterparts. Here’s a sample:

Abrams = أبرامز
Abramson = أبرامسون
Abrasion = الجرح
Abrasions = الجروح
Abrasive = المزيل
Abrasively = بخشونة
Abrasiveness = الحكّ
Abrasives = المزيلات
Abreact = حرّر
Abreacted = حرّر
Abreacting = تخليص من العقد
Abreaction = تحرّر من عقدة نفسيّة
Abreactions = تحرّر من عقدة نفسيّة
Abreacts = يحرّر
Abreast = جنبًا إلى جنب
Abridge = اختصر
Abridged = اختصر
Abridgement = الاختصار
Abridgements = الاختصارات
Abridger = الملخّص
Abridges = يختصر
Abridging = الاختصار
Abridgment = الاختصار
Abroad = بالخارج
Abrogate = ألغ
Abrogated = ألغى
Abrogates = يلغي

The goal: [i]To explode all of the Arabic words in to an array[/i].

I am guessing I’ll need to use preg_replace() to take out the english words and the extraneous spaces, and then use explode() to get all of the Arabic words in to an array.

HELP!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJul 03.2008 — try something like this

[code=php]
// create Arabic Array
$arabic_arr = Array();

// Read file into string
$str = file_get_contents('/path/to/file.txt');

// explode on equal sign = into array
$arr = explode("=",$str)

foreach($arr as $key => $value)
{
// filter out Engilsh
if(!preg_match("/^[a-zA-Z]+$/", $value))
{
// trim
$value = trim($value);

// Push to new array
array_push($arabic_arr, $value);
}
}

// to see the value of the Arabic Array
print_r($arabic_arr);

[/code]
Copy linkTweet thisAlerts:
@NogDogJul 03.2008 — This might work:
[code=php]
$text = file_get_contents('path/to/file');
preg_match_all('/=s*([^rn]+)(?:[rn]|$)/', $text, $matches);
print_r($matches[1]); // $matches[1] contains first regexp sub-pattern matches
[/code]
Copy linkTweet thisAlerts:
@callumdauthorJul 03.2008 — Thanks guys,

I'll try them out.
Copy linkTweet thisAlerts:
@XlayerJul 04.2008 — This might work:
[code=php]
$text = file_get_contents('path/to/file');
preg_match_all('/=s*([^rn]+)(?:[rn]|$)/', $text, $matches);
print_r($matches[1]); // $matches[1] contains first regexp sub-pattern matches
[/code]
[/QUOTE]


short, very nice ! Thanks. ?
×

Success!

Help @callumd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...