Jump to content

Regex or explode to array: I need some help in a simple string!


dilbertone

Recommended Posts

good day dear community,

 

well i am in big big trouble - i need some regex to solve a problem! Can you help me a bit! That would be great! Well - i mused alot how to call the subject: Finally i came to: "Regex or explode to array: I need some help in a simple string!"

 

i have a spreadsheed in calc. with some records. There is a column that contains the following information

 

Ecole Saint-Exupery

Rue Saint-Malo 24

67544 Paris

 

Well i need to have those lines divided into at least three columns

 

name: Ecole Saint-Exupery

street: Rue Saint-Malo 24

postal code and town 67544 Paris

 

Or even better - i have divided the postal code and town into two seperate columns!? Question: is this possible? Can (or should) i do this in calc (open document-formate)? Do i need to have to use a regex and perl or am i able to solve this issues without an regex?

 

Note - finally i need to transfer the data into MySQL-database...

 

I look forward to a tipp...

 

greetings

 

BTW: you can see all the things in a real world-live-demo: http://192.68.214.70/km/asps/schulsuche.asp?q=a&a=50&s=1750 - see the filed

 

Schulname

Straße

PLZ Ort

 

These field contains three things - the name, the street and the Postal Code and the town! Question: can this be divided into parts!? If you copy and paste the information - and drop it to calc then you get all the information in only one cell. How to divide and seperate all those information into three cells or even four?

 

BTW - i tried to translate the information to hex-code - see the follwoing...:

 

Staatl. Realschule Grafenau

Rachelweg 20

94481  Grafenau

 

00000000: 53 74 61 61 74 6C 2E 20  52 65 61 6C 73 63 68 75
00000010: 6C 65 20 47 72 61 66 65  6E 61 75 20 0A 52 61 63
00000020: 68 65 6C 77 65 67 20 32  30 0A 39 34 34 38 31 20
00000030: 20 47 72 61 66 65 6E 61  75 20 20 

 

but i do not know if this helps here!??

 

Can you help me to solve the problem. Do i need to have a regex!?

 

Many thanks in advance for any and all help!

Link to comment
Share on other sites

hello dear The Little Guy

 

many many thanks for the hints! GREAT!

 

$opt = explode("\n", $record);
var_dump($opt);

 

 

well did i get you right: i take the information of the  third column in this huge spreadheet that can be found here  http://192.68.214.70/km/asps/schulsuche.asp?q=a&a=50&s=1750

 

(or the information that is derived from this dataset to a calc-Spreadsheet) and apply your code on the third  (!!!) Column of the Spreadsheet ?

 

Note - i need to have the information not only in one cell but in three or four!?

 

Question: should i take the information of the huge (note the table contains almost 6000 records)

 

 

The Little Guy - i love to hear from you again. ..

 

best regards

db1  ;D

Link to comment
Share on other sites

Hello TLG

 

yes  - i want to split that information to tree cells or columns (in MySQL)

 

BTW see the dataset: here you have an overview:  http://192.68.214.70/km/asps/schulsuche.asp?q=a&a=50&s=1750

 

Well - i have loaded the data of the online sheet to a calc-spreadsheet and from there i imported it to mysql.

 

In only one Column (the third one!) i have the full adress with

 

1. name of the school

2. name of the street

3. postal code and town

 

Well  - i guess that your code hits the point. I take all the (almost 6000 ) records and apply your code below.

 

 

If I understand correctly, you would want something like this:

 

$opt = explode("\n", $record); // Don't forget to mysql_real_escape_string
mysql_query("INSERT INTO my_table (name, street, postal) VALUES ('{$opt[0]}','{$opt[1]}','{$opt[2]}')");

 

i will have a closer look what explode does exactly. But i am pretty sure that you have given the exact hint....

 

Best regards

db1

 

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.