CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2313|Reply: 2

PHP & regular expression (ereg maybe?)

[Copy link]
Post time 5-9-2007 12:46 PM | Show all posts |Read mode
Lis ada masalah mcm ni:
  1. $mystring = "Name (NAM), Area Measure (sq m) (ARM), Tank Type (TAT), Tank Usage (TAU)";
Copy the Code


Macamana Lis nak amik hanya NAM, ARM, TAT, dan TAU dari string tu dan simpan dalam satu array? cth:
  1. $val[0]='NAM';
  2. $val[1]='ARM';
  3. $val[2]='TAT';
  4. $val[3]='TAU';
Copy the Code


utk makluman semua, ada byk lagi kod yg ada, bukan hanya NAM, ARM, TAT, TAU tu... tapi struktur tetap sama iaitu:
- 3 ABJAD
- Uppercase
- enclosed in bracket

jumlah elemen utk sesuatu string tu tak tentu, boleh jadi 1, 2, 3, 4, .....
Reply

Use magic Report


ADVERTISEMENT


Post time 6-9-2007 08:39 AM | Show all posts
n ikut cara aku yang tak berapa pandai n....

<?php

$mystring = "Name (NAM), Area Measure (sq m) (ARM), Tank Type (TAT), Tank Usage (TAU)";

echo $mystring.'<br>';

$a = split(',', $mystring);
for ($i=0; $i<count($a); $i++) {
        $b[] = strstr($a[$i],'(');
}
print_r($b);

?>

masalahnya.... kalau ada value  Area Measure (sq m) (ARM) ... cuba tukarkan ke Area Measure [sq m] (ARM)
tah la... kalau ada expert lain bagi idea ok gak
Reply

Use magic Report

 Author| Post time 6-9-2007 12:21 PM | Show all posts

Reply #2 BorderManager's post

tima kasih..

Nak tukar yg (sq m) tu kepada [sq m] akan jadi masalah sbb ada byk bentuk yg perlu dilakukan .. bukan hanya 'sq m' je.. ada lagi bentuk lain2

kalau dalam bentuk regular expression, Lis ada tefikir pattern mcm ni
  1. \([A-Z]{3}\)
Copy the Code

tapi masalahnya hanya match satu je yg pertama
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

3-1-2025 03:12 AM GMT+8 , Processed in 0.041596 second(s), 16 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list