Jump to content

Archived

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

xam

Need help..

Recommended Posts

Hello,

I use below code to change my language files.

[code]<?php
session_start();
function addslashes2 ($string) {
if (!get_magic_quotes_gpc())
  return str_replace('\'','\\\'',$string);
else
  return str_replace('\'','\\\'',stripslashes($string));

}
if (isset($_POST['new_lang'])):
    $current_lang = $_SESSION['lang'];
    $new_lang_file_content = array();
    foreach ($_POST['new_lang'] as $key => $value):
          $new_lang_file_content[] = '$lang[\''.$key.'\'] = \''. addslashes2($value) .'\';';
    endforeach;
    $handler = fopen('lang.inc','w');
    fwrite($handler,"<?php\n".implode("\n",$new_lang_file_content)."\n?>");
    fclose($handler);
    Die ('Language file has been updated. Click <a href=javascript:history.go(-1)> here</a> to go back.');
endif;
include_once 'lang.inc';
echo $lang['category'];
?>
<form method="post">
<input name="new_lang[category]" type="text" value="<?=$lang['category'];?>">
<input type="submit"></form>[/code]

It works fine but I need some help about; When I insert a text with php string into input area, e.g. following text: You have been redirected to main page '.$MAIN['mainpage'].'
It save it as a text I want to save it as php string, take a look at below example thats what I want..

e.g.:
I wrote: You have been redirected to main page '.$MAIN['mainpage'].'
It has been saved as (lang.inc):
[code]<?php
$lang['category'] = 'You have been redirected to main page \'.$MAIN[\'mainpage\'].\' ';
?>[/code]

I want:

[code]
<?php
$lang['category'] = 'You have been redirected to main page '.$MAIN['mainpage'].' ';
?>[/code]

without slashes..

Share this post


Link to post
Share on other sites
[url=http://www.php.net/manual/en/function.stripslashes.php]stripslashes()[/url]

Orio.

Share this post


Link to post
Share on other sites
[quote author=Orio link=topic=99045.msg389894#msg389894 date=1151701226]
[url=http://www.php.net/manual/en/function.stripslashes.php]stripslashes()[/url]

Orio.
[/quote]

ok done, thx

Share this post


Link to post
Share on other sites
well, I have another question / I need another help..

An example language file content:
language.php
[code]$lang['Copyright'] = 'Copyright '.$Settings['url'].' All Rights Reserved.';[/code]

An example modify script for language file:
[code]
include_once ('language.php');
echo '<input onClick="highlight(this);" size="200" type="text" name="new_lang[Copyright]" value=" '.$lang['Copyright'].' ">'
[/code]

It shows:
[code]<input onClick="highlight(this);" size="200" type="text" name="new_lang[Copyright]" value="Copyright  All Rights Reserved.">[/code]

I want:
[code]<input onClick="highlight(this);" size="200" type="text" name="new_lang[Copyright]" value="Copyright '.$lang['Copyright'].'  All Rights Reserved.">[/code]

$settings[xxxx] values should be write as text content..
I use htmlspecialchars but It wont help ...

Share this post


Link to post
Share on other sites
Do you mean this
[code=php:0]
$lang['Copyright'] = 'Copyright  All Rights Reserved.';

echo  $lang['Copyright']; //-->  Copyright  All Rights Reserved.
echo '<br>';
    // text in single quotes
echo  '$lang[\'Copyright\']'; //-->  $lang['Copyright'];[/code]

Share this post


Link to post
Share on other sites
Hi,
  I have this error and I know it is an empty string but I cannot find where is my mistake. Anyone can tell me where is my mistake.

My coding
  // update asset
                        $sql = "UPDATE Assets SET financetag='" . $assettype_id  . $assettag . "',assettype='" . $assettype . "',assetsupplier='" . $assetsupplier . "',assetmodel='" . $assetmodel . "',assetserial='" . $assetserial . "',assetprice='" . $assetprice .  "',description='" . $assetdescription . "',make='" . $assetmake . "',year='" . $assetyear . "',rego='" . $assetrego . "',notes='" .  $notes . "' WHERE id=" . $key . ";";
                        if ($result = doSql($sql)) {

An error occurred while attempting to update the database. Please contact the webmaster. This is action attempted:: INSERT INTO Assets (financetag,assettype,assetsupplier,assetmodel,assetserial,assetprice,description,make,year,rego,status,notes,added_by, date_added) VALUES ('1691751','sdsd','16','','','0','','','2006','','','', '1', '2006-07-01 15:09:11');
Duplicate entry '' for key 2

Eunice

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=99045.msg390167#msg390167 date=1151765522]
Do you mean this
[code=php:0]
$lang['Copyright'] = 'Copyright  All Rights Reserved.';

echo  $lang['Copyright']; //-->  Copyright  All Rights Reserved.
echo '<br>';
    // text in single quotes
echo  '$lang[\'Copyright\']'; //-->  $lang['Copyright'];[/code]
[/quote]

no, I mean:
$lang['leecher'] = 'This page is only avaliable from the '.$MAIN['url'].' site.';

The code:
<input onClick="highlight(this);" size="200" type="text" name="new_lang[leecher]" value="'.$lang['leecher'].'">

It shows:
<input onClick="highlight(this);" size="200" type="text" name="new_lang[leecher]" value="This page is only avaliable from the  site.">

It should be:
<input onClick="highlight(this);" size="200" type="text" name="new_lang[leecher]" value="This page is only avaliable from the '.$MAIN['url'].' site.">

It must show '.$MAIN['url'].' string as text not a php value/string..

Share this post


Link to post
Share on other sites
Does anyone help me about that my problem ????

???

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=99045.msg390167#msg390167 date=1151765522]
Do you mean this
[code=php:0]
$lang['Copyright'] = 'Copyright  All Rights Reserved.';

echo  $lang['Copyright']; //-->  Copyright  All Rights Reserved.
echo '<br>';
    // text in single quotes
echo  '$lang[\'Copyright\']'; //-->  $lang['Copyright'];[/code]
[/quote]

I already have

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=99045.msg390437#msg390437 date=1151836056]
[quote author=Barand link=topic=99045.msg390167#msg390167 date=1151765522]
Do you mean this
[code=php:0]
$lang['Copyright'] = 'Copyright  All Rights Reserved.';

echo  $lang['Copyright']; //-->  Copyright  All Rights Reserved.
echo '<br>';
    // text in single quotes
echo  '$lang[\'Copyright\']'; //-->  $lang['Copyright'];[/code]
[/quote]

I already have
[/quote]

I mean:
lang-en.php
[code=php:0]
$lang['protected2'] = 'Copyright '.$MAIN['url'].' All Rights Reserved.';
[/code]

Form (to change/edit language text in adminpanel):
[code=php:0]
echo '<input onClick="highlight(this);" size="200" type="text" name="new_lang[protected2]" value="'.$lang['protected2'].'"><br>';
[/code]

Output (to input value):
<input onClick="highlight(this);" size="200" type="text" name="new_lang[protected2]" value="Copyright All Rights Reserved.">

I want:
Output (to input value):
<input onClick="highlight(this);" size="200" type="text" name="new_lang[protected2]" value="Copyright '.$MAIN['url'].'  All Rights Reserved.">

Share this post


Link to post
Share on other sites
http://uk.php.net/manual/en/language.types.string.php

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=99045.msg391003#msg391003 date=1151940373]
http://uk.php.net/manual/en/language.types.string.php
[/quote]

Its hard for me ;( my english not enought for this tutorial thats why I wrote here....

???

Share this post


Link to post
Share on other sites

×

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.