Skip to main content
Inspiring
August 10, 2011
Question

Split text in field into two boxes

  • August 10, 2011
  • 2 replies
  • 1116 views

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?

This topic has been closed for replies.

2 replies

Inspiring
August 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

Lon_Winters
Inspiring
August 10, 2011

What exactly is contained in the one database field?

Inspiring
August 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!

Inspiring
August 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!)


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