Jump to content

[SOLVED] endless loop? empty variables? what IS going on?


dsaba

Recommended Posts

hello everyone! i'm having a problem with a loop

1. it appears to be endless, as it freezes up my browser and never really ends

2. the variables are empty in the loop period

 

<?php


#scenario 2, 1 file with english=translation
$fileArray = file('es-translations.txt') or die("cannot make array out of file lines");
//print_r($fileArray);


for ($i=0; $i=count($fileArray); $i++) {
echo '<br>'.$fileArray[$i];
$full_line = explode("=", $fileArray[$i]);
$english = str_replace("", "_", trim($full_line[0]));
$translation = trim($full_line[1]);

$string = 'define('.$english.', "'.$translation.'", TRUE);';
echo '<br>'.$string;
}

?>

the end output should be:

define(some_words_like_this, "some other words like this", TRUE);

 

what it outputs is:

define(, "", TRUE);

 

i print_r($fileArray) and it did indeed have values

 

so two problems I see:

1. endless loop

2. empty variables

 

Any ideas?

-thanks

Could you post some demo data stored in es-translations.txt

 

Also this line is weird:

$english = str_replace("", "_", trim($full_line[0]));

Your are replacing nothing with an underscore :o - You might want to place the first two parameters for the str_replace function the other way around. That way you replace underscores with nothing. You cant replace nothing with something.

In this line

<?php
$english = str_replace("", "_", trim($full_line[0]));
?>

 

Are you sure you want to replace the null string with "_"?  Maybe you want to replace all " " (spaces characters) with "_".

 

Ken

 

all the lines look like this in es-translations.txt

 

optional not disclosed= opcional no cerrado

OR optional not disclosed=opcional no cerrado

 

i am replacing the english phrases to: optional_not_disclosed

 

so it will look like:

define(optional_not_disclosed, "opcional no cerrado", TRUE);

 

and someone told me I need to make the for statement like this:

for ($i=0; $i<count($fileArray); $i++) {

 

so i'm going to try that out now

 

yeah that works i wasn't using the FOR statement correctly

and i will do str_replace " ", with "_" as well

that should fix it

 

thanks for the help!

Here's a shorter version of your code:

<?php
$fileArray = file('es-translations.txt') or die("cannot make array out of file lines");
//print_r($fileArray);
$tmp = array();
foreach ($fileArray as $val) {
list($english, $translation) = explode("=", $val);
$tmp[] = 'define('. trim(str_replace(' ','_',$english)) .', "'. trim($translation) .'", TRUE);';
}
echo implode('<br>',$tmp).'<br>';
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.