Question about Arrays from php and arrays from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nickiz
    New Member
    • Jan 2007
    • 1

    Question about Arrays from php and arrays from mysql

    Hello, i'm trying to create a simple converter application using php. The main function i use is strtr() that can translate from $string via arrays.

    Because the arrays need to add in the file php, so it is difficult to user add their own word in this application. I was create a database that contain 2 fields. The question is how the script to write.


    [PHP]

    $phonArray=arra y(
    'abaian'=>'اباي ن','abbas'=>'عب اس','abd'=>'عبد ','abdal'=>'ابد ال','abdas'=>'ا بدس','abdi'=>'ع بدي',);

    $input="Some Texts Here....";//from form

    //How to make this $input read from the database first and then proceed to next function strtr() bellow.

    $output= strtr($input, $phonArray);

    echo"$output";

    [/PHP]
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by nickiz
    Hello, i'm trying to create a simple converter application using php. The main function i use is strtr() that can translate from $string via arrays.

    Because the arrays need to add in the file php, so it is difficult to user add their own word in this application. I was create a database that contain 2 fields. The question is how the script to write.


    [PHP]

    $phonArray=arra y(
    'abaian'=>'اباي ن','abbas'=>'عب اس','abd'=>'عبد ','abdal'=>'ابد ال','abdas'=>'ا بدس','abdi'=>'ع بدي',);

    $input="Some Texts Here....";//from form

    //How to make this $input read from the database first and then proceed to next function strtr() bellow.

    $output= strtr($input, $phonArray);

    echo"$output";

    [/PHP]
    [PHP]
    //your array
    $phonArray=arra y(
    'abaian'=>'اباي ن','abbas'=>'عب اس','abd'=>'عبد ','abdal'=>'ابد ال','abdas'=>'ا بدس','abdi'=>'ع بدي',);

    //database info
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'password';

    //connect to db
    $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    //select db & run query
    $dbname = 'translator';
    mysql_select_db ($dbname);
    $result = mysql_query('SE LECT * WHERE ID="0"');
    $row = mysql_fetch_row ($result);
    $input = $row[0];

    //close db
    mysql_close($co nn);

    //continue
    $output= strtr($input, $phonArray);

    echo"$output";
    [/PHP]
    Last edited by b1randon; Jan 9 '07, 12:52 AM. Reason: typo

    Comment

    Working...