Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Split text in field into two boxes

Participant ,
Aug 10, 2011 Aug 10, 2011

Hiya

I am setting up a bi-lingual website where the left hand column is in English and the matching right hand column is in French.

Is there a way to use ONE field from the database and split the information like this:

<special tag here around English>

English Text

English Text

English Text

</special tag here around English>

<special tag here around French>

French Text

French Text

French Text

</special tag here around French>

Any ideas?

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 10, 2011 Aug 10, 2011

What exactly is contained in the one database field?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 10, 2011 Aug 10, 2011

The text for the web page. So details about the school (in French first). Then the same text translated into English.

I know adding another column to the DB would be easier on the page, but as I am making the changes to a Wordpress blog it would be a nightmare to coordinate the different versions of the page in both French and English.

All I really need is to make this schematic work:

if ( $frenchTag . $the_Text_in_French . $endFrenchTag ) { echo $the_Text_in_French }    // this goes in the french text box

if ( $englishTag . $the_Text_in_English . $endEnglishTag ) { echo $the_Text_in_English }    // this goes in the english text box

I know the sytax is all over the place, but that is what I need help with please!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2011 Aug 11, 2011

Cludgy way:

Fill your field as follows [En francais#&&#In English] - i.e. #&&# is unlikely to be input elsewhere as normal text, then use

explode:

$fieldtext = explode('#&&#', yourfield);

In the French box: echo $fieldtext(0);

In the English box: echo $fieldtext(1);

Better way:

Use preg_replace or preg_split (but you will have to ask someone more experienced than me to help you with the regular expression!)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 11, 2011 Aug 11, 2011

Hiya,

Thanks for your help. I had no idea this is what expode did! I have tried this on a test page, but get an error saying:

Fatal error: Function name must be a string in /content/HostingPlus/w/a/waltoncreative.com/web/LeHerisson/test.php on line 55

This is the script:  (using -999- to separate the French / English)

<?php $fieldtext = explode('-999-', $row_ToSeparateText['test_Text']); ?>

All of the text<br />

<?php echo($row_ToSeparateText['test_Text']); ?>

<hr />

French Text<br /><?php echo $fieldtext(1); ?>      <<<<    this is line 55

<hr />

English Text<br /><?php echo $fieldtext(0); ?>

But this is what I get on screen:

All of the text
This is a nice long chunk of text to see if I can split it up with a character that looks like this.-999-Cette est une petite sample des mots pour le teste.


French Text

Fatal error: Function name must be a string in /content/HostingPlus/w/a/waltoncreative.com/web/LeHerisson/test.php on line 55

The character is in the field, so what have I missed?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 11, 2011 Aug 11, 2011

I found the answer - the echo numbers needed SQUARE brackets:

So this works:

<?php $fieldtext = explode('-999-', $row_ToSeparateText['test_Text']); ?>

All of the text<br />

<?php echo($row_ToSeparateText['test_Text']); ?>

<hr />

French Text<br /><?php echo $fieldtext[1]; ?>

<hr />

English Text<br /><?php echo $fieldtext[0]; ?>

Thanks for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2011 Aug 12, 2011
LATEST

Sorry Colin, I must have been rushing when I used the wrong brackets! Glad it worked for you.

Ed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 10, 2011 Aug 10, 2011

You could, but it's asking for trouble.

If you will forever be only bilingual (and not multilingual) you could add a field (column) and have English in one, French in the other. If you will ever be going multilingual then add a field to identify the language (language_id or whatever) and a new record (row) for each entry. In either case you will need to deal with blank/missing entries.

Ed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines