Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
What exactly is contained in the one database field?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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!)
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Sorry Colin, I must have been rushing when I used the wrong brackets! Glad it worked for you.
Ed
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now