By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Regular expression help

P: 2
Hi guys

I have a case where data is getting stored in the database as: <!--:en-->Energy<!--:--><!--:fr-->Energies<!--:-->

Now in a given page, I have en or fr, and based on that I need to get the corresponding value.

For example, if I have
Expand|Select|Wrap|Line Numbers
  1. $title    = '<!--:en-->Energy<!--:--><!--:fr-->Energies<!--:-->';
  2. $lng     = 'fr';
  3. $title     = preg_replace('/<!--:'.$lng.'-->(.*?)<!--:-->/i', '$1', $title); 
  4.  
I want to get "Energies" by echoing $title.

Any idea ?

PS. The preg_replace is just there for an example, I know the code is not working.
Feb 26 '12 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
I have a case where data is getting stored in the database as: <!--:en-->Energy<!--:--><!--:fr-->Energies<!--:-->
from the overall point-of-view this is the main problem. a DB column should not contain aggregated data. it would be more sensible to have a field for the word and another field for the language, so you can switch between languages by making the appropriate query.


for the quick'n'dirty fix, you need the non-greedy modifier in your RegExp.
Feb 27 '12 #2

P: 2
Thanks Dormilich. Yes, this is not a good DB design, but it's the qTranslate plugin of Wordpress, that allows to have a multilingual website.

So basically I need a quick'n'dirty fix. However, how to rewrite that code with a non-greedy modifier Dormilich?

Thanks for your reply again, non-greedy modifier
Feb 27 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
Yes, this is not a good DB design, but it's the qTranslate plugin of Wordpress, that allows to have a multilingual website.
if possible, use another plugin.


you should look up regular expressions (ref.), even I have to look up such things.
Feb 27 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.