neeed help to convert script to utf-8 ....

Discussion in 'Programming' started by someone100, Nov 3, 2008.

  1. #1
    this is phpas code of function . please tell me the principle so i can convert it to support utf-8 :)

    i show only part of it because i don't want to violate script licence .
    thanks


    
    .....
    
    }
    
    if (!($limit)){
    $limit = $max_results;} // Default results per-page.
    if (!($page)){
    $page = 0;} // Default page value.
    if (!$searchterm)
    $sql_query = "SELECT * from games WHERE gamestatus = 1 $browseby";
    else
    $sql_query = "SELECT * from games WHERE gamestatus = 1 AND (gametitle LIKE \"%$searchterm%\" OR gamedesc LIKE  \"%$searchterm%\" OR gamekeywords LIKE \"%$searchterm%\" OR instructions LIKE \"%$searchterm%\" OR gamefile LIKE \"%$searchterm%\")";
    $numresults = mysql_query($sql_query); // the query.
    $numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
    
    
    if (!empty($searchterm)){
    // LOG SEARCH RESULTS
          $searchterm2 = strtolower($searchterm);
          
          $now = time();
          
          // If its already been searched for, then increase the number of searches by one
          $sql = "SELECT count(id) AS already_searched from searches WHERE searchterm = '$searchterm2'";
          //store the SQL query in the result variable
          $result = @mysql_query($sql);
          $i = mysql_fetch_array($result); 
          $already_searched = $i['already_searched']; 
    
          if ($already_searched > 0)
          $update_search = mysql_query("UPDATE searches
          set amount = amount + 1,
          results = '$numrows',
          date = '$now'
          where searchterm = '$searchterm2'");
          
          else
          $insert_search = mysql_query("INSERT into searches
          set amount = '1',
          date = '$now',
          searchterm = '$searchterm2',
          results = '$numrows'");
          
          // Now we need to get the search ID just IF SE FRIENDLY IS TURNED ON
                $search_query = "SELECT * FROM searches WHERE searchterm = '$searchterm2' LIMIT 1";
                //store the SQL query in the result variable
                $search_result = mysql_query($search_query);
                if(@mysql_num_rows($search_result))
                {
                //output as long as there are still available fields
                while($row = mysql_fetch_array($search_result))
                {
                $searchid = $row['id'];
                $searchterm = stripslashes($row['searchterm']);
                $searchlink = make_friendly($searchterm);
                }
                }
          
    // END SEARCH LOGGING
    }
    
    
    if ($numrows == 0){
      // If no games can be found, then it displays the following
      $content.="<div align=\"center\">No Games Listed</div>";
    }
    else{
            $pages = intval($numrows/$limit); // Number of results pages.
            
            // $pages now contains int of pages, unless there is a remainder from division.
            
            if ($numrows%$limit) {
            $pages++;} // has remainder so add one page
            
            $current = ($page/$limit) + 1; // Current page number.
            
            if (($pages < 1) || ($pages == 0)) {
            $total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
            
            else {
            $total = $pages;} // Else total pages is $pages value.
            
            $first = $page + 1; // The first result.
            
            if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
            $last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
             
            else{
            $last = $numrows;} // If last results page, last result equals total number of results.
            
            // Now we can display results.
            $results = mysql_query("$sql_query LIMIT $page, $limit");
            $number_of_results = 0;
            $number_of_results_adsense = 0;
            while ($data = mysql_fetch_array($results))
            {
                   
    
    
     .......
    
    
    
    
    ?>
    
    
    PHP:
     
    someone100, Nov 3, 2008 IP
  2. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #2
    make sure you send in the
    header ('Content-Type: text/html; charset=utf-8');
    Code (markup):
    since php5 utf8 is no more a problem, at least for me.

    on some server you may also need to send the utf8 stuff with the meta-tags of the html.
    had that issue on some server.

    so add
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    Code (markup):
    in your html.

    also your db should be in UTF8
     
    happpy, Nov 3, 2008 IP
  3. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    happpy , i think you are not in right direction . i have put this meta in all my files :(
     
    someone100, Nov 3, 2008 IP
  4. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #4
    aha, and its a lot of files??
    well, zip up all the files where meta & header should be applied.

    send them to me. i pmed you my email.

    i can batch-apply these.
     
    happpy, Nov 3, 2008 IP
  5. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i have done it all :) for all files . this file is a function which server the site and not a page inside it .

    
    <?php 
    
    $items_per_row=8;
    
    
    /*
    script: browse.php
    purpose: browsing script - this script handles all the browsing of the arcade games.
    copyright: copyright 2005-2008 phpArcadeScript & Scott Lewis. All Rights Reserved. You may modify this file for use on your
    					site running a licenced copy of phpArcadeScript.
    					You must not distribute this file or derivations of it.
    support: www.phparcadescript.com
    
    */
    
    // This determines if we are browsing by all games or a specific category. The first one
    // means since they isn't a category id specified we are going to browse all games
    
    
    
    PHP:
     
    someone100, Nov 3, 2008 IP
  6. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #6
    dont know what you want to say by this,
    but
    some people say THANKS if they are helped....
     
    happpy, Nov 3, 2008 IP
  7. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    happpy , maybe my english not so good .
    the problem wan not solved :(
    all you have suggested i already have done before asking the first question .

    you are very positive and thanks for that . i really say this .

    i think the problem is in that i have not done .
    i could be to to write some sort off addon to search tearm so the sql can be done or some other method .

    i will publish the full page of script . maybe it help :




    
    
    <?php 
    
    $items_per_row=8;
    
    
    /*
    script: browse.php
    purpose: browsing script - this script handles all the browsing of the arcade games.
    copyright: copyright 2005-2008 phpArcadeScript & Scott Lewis. All Rights Reserved. You may modify this file for use on your
    					site running a licenced copy of phpArcadeScript.
    					You must not distribute this file or derivations of it.
    support: www.phparcadescript.com
    
    */
    
    // This determines if we are browsing by all games or a specific category. The first one
    // means since they isn't a category id specified we are going to browse all games
    
                  $template = file_get_contents("./templates/$template_directory/item.html");
                  
                  $maintemplate = file_get_contents("./templates/$template_directory/browse.html");
       
                  $template = universal_template_codes($template);
       
                  $maintemplate = universal_template_codes($maintemplate);
    
    
    if ($rewrite != '0')
    {
        if (!$browse_cat_name && !$searchterm)
        $browseby = "ORDER BY gametitle ASC";
       
        // Since a category id was supplied, we will browse all the games in the specific category
        elseif (!$browse_cat_name)
        {
        }
      
        else
        $browseby = "AND (category = $browse_cat_id $child_cat_ids) ORDER BY gametitle ASC";
    
    }
    
    else
    {
        if (!$cat && !$searchterm)
        $browseby = "ORDER BY gametitle ASC";
        
        // Since a category id was supplied, we will browse all the games in the specific category
        
        else
        $browseby = "AND (category = '$cat' $child_cat_ids) ORDER BY gametitle ASC";
    
    }
    
    if (!($limit)){
    $limit = $max_results;} // Default results per-page.
    if (!($page)){
    $page = 0;} // Default page value.
    if (!$searchterm)
    $sql_query = "SELECT * from games WHERE gamestatus = 1 $browseby";
    else
    $sql_query = "SELECT * from games WHERE gamestatus = 1 AND (gametitle LIKE \"%$searchterm%\" OR gamedesc LIKE  \"%$searchterm%\" OR gamekeywords LIKE \"%$searchterm%\" OR instructions LIKE \"%$searchterm%\" OR gamefile LIKE \"%$searchterm%\")";
    $numresults = mysql_query($sql_query); // the query.
    $numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
    
    
    if (!empty($searchterm)){
    // LOG SEARCH RESULTS
          $searchterm2 = strtolower($searchterm);
          
          $now = time();
          
          // If its already been searched for, then increase the number of searches by one
          $sql = "SELECT count(id) AS already_searched from searches WHERE searchterm = '$searchterm2'";
          //store the SQL query in the result variable
          $result = @mysql_query($sql);
          $i = mysql_fetch_array($result); 
          $already_searched = $i['already_searched']; 
    
          if ($already_searched > 0)
          $update_search = mysql_query("UPDATE searches
          set amount = amount + 1,
          results = '$numrows',
          date = '$now'
          where searchterm = '$searchterm2'");
          
          else
          $insert_search = mysql_query("INSERT into searches
          set amount = '1',
          date = '$now',
          searchterm = '$searchterm2',
          results = '$numrows'");
          
          // Now we need to get the search ID just IF SE FRIENDLY IS TURNED ON
                $search_query = "SELECT * FROM searches WHERE searchterm = '$searchterm2' LIMIT 1";
                //store the SQL query in the result variable
                $search_result = mysql_query($search_query);
                if(@mysql_num_rows($search_result))
                {
                //output as long as there are still available fields
                while($row = mysql_fetch_array($search_result))
                {
                $searchid = $row['id'];
                $searchterm = stripslashes($row['searchterm']);
                $searchlink = make_friendly($searchterm);
                }
                }
          
    // END SEARCH LOGGING
    }
    
    
    if ($numrows == 0){
      // If no games can be found, then it displays the following
      $content.="<div align=\"center\">No Games Listed</div>";
    }
    else{
            $pages = intval($numrows/$limit); // Number of results pages.
            
            // $pages now contains int of pages, unless there is a remainder from division.
            
            if ($numrows%$limit) {
            $pages++;} // has remainder so add one page
            
            $current = ($page/$limit) + 1; // Current page number.
            
            if (($pages < 1) || ($pages == 0)) {
            $total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
            
            else {
            $total = $pages;} // Else total pages is $pages value.
            
            $first = $page + 1; // The first result.
            
            if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
            $last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
             
            else{
            $last = $numrows;} // If last results page, last result equals total number of results.
            
            // Now we can display results.
            $results = mysql_query("$sql_query LIMIT $page, $limit");
            $number_of_results = 0;
            $number_of_results_adsense = 0;
            while ($data = mysql_fetch_array($results))
            {
                    $number_of_results++;
                    $rating = $data['rating'];
                    $number_of_votes = $data['totalvotes'];
                    $gamedesc = stripslashes($data['gamedesc']);
                    $gametitle = $data['gametitle'];
    
    
    
                    $gametitle = stripslashes($gametitle);
    		$title = make_friendly($gametitle);
    		if(strlen($gametitle)>10)
                    $gametitle = substr($gametitle,0,7)."..";
                    $gameid = $data['gameid'];
                    $timesplayed = $data['timesplayed'];
                    $gamelocation = $data['gamelocation'];
                    $iconlocation = $data['iconlocation'];
                    $gameicon = $data['gameicon'];
                    
                    $star = get_rating($rating,$number_of_votes,$base_url);
                    
                        
                    if ($iconlocation == 1)
                    $gameicon = $gameicon;
                    elseif (!empty($gameicon))
                    $gameicon = $base_url."games/images/".$gameicon;
                    
                    if (empty($gameicon))
                    $gameicon = $defaulticon;
                    
                    if ($rewrite ==0)
                    $gamelink = $base_url."index.php?action=playgame&gameid=".$gameid;
                    else
                    $gamelink = $base_url.$sedir."/".$gameid."/".$title;
            	   
         
                    $bodytags = array(
                    
                                "%display_game%", // Where the game will be displayed
                                "%gameid%", // ID for the Game
                                "%gamelink%", // URL to the game page
                                "%gametitle%", // Title of the Game
                                "%gamedescription%", // Description of the Game
                                "%gamekeywords%", // Keywords for the game
                                "%timesplayed%", // Times the game has been played
                                "%rating%", // Current Game Rating
                                "%gameicon%", // The Game Icon
                   
                    );
      
                   $bodyreplacements = array(
      
                                "$file_display", // Where the game will be displayed
                                "$gameid", // ID for the Game
                                "$gamelink", // URL to the game page
                                "$gametitle", // Title of the Game
                                "$gamedesc", // Description of the Game
                                "$gamekeywords", // Keywords for the game
                                "$timesplayed", // Times the game has been played
                                "$rating", // Current Game Rating
                                "$gameicon", // The Game Icon
                                                
                    );
      
                    $content.= str_replace($bodytags,$bodyreplacements,$template);
                    
                  if($items_per_row>0)
                    if($number_of_results==$items_per_row){
                      $content.="<div style=\"clear:both;\"></div>";
                      $number_of_results=0;
                    }
            
            }
    
                    if($number_of_results>0){
                      $content.="<div style=\"clear:both;\"></div>";
                    }
    
            
    }
    
            ob_start(); //start output buffer
            include ("./includes/paginate.php");
            $pagenumbers = ob_get_contents(); //$page = output buffer's contents
            ob_end_clean(); //end output buffer
            
            if (empty($searchid))
            $subcategories = display_sub_categories($rewrite,$base_url,$browse_cat_id);
    	$googlead  =  "<br/>".display_ad(5,$base_url);
    
    
                    $bodytags = array(
                    
                                "%pagetitle%", // Title of the Page
                                "%subcategories%", // The Sub-categories
                                "%content%", // The main content for the page
                                "%pagenumbers%", // The page numbers
    			    "%googlead%", // google ad
                   
                    );
      
                   $bodyreplacements = array(
    
                                "$pagetitle", // Title of the Page
                                "$subcategories", // The Sub-categories
                                "$content", // The main content for the page
                                "$pagenumbers", // The page numbers
    			    "$googlead", // googlead
                                                
                    );
      
                    $content = str_replace($bodytags,$bodyreplacements,$maintemplate);
    
    echo $content;
    
    ?>
    
    
    PHP:
     
    someone100, Nov 3, 2008 IP
  8. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
  9. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #9
    i dont really get what you wanna do.

    sounds like you wanna convert your mysql-database to utf8

    try this one

    ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
     
    happpy, Nov 3, 2008 IP
  10. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    thanks . i will try again :

    I WANT TO my site www.smgames.net
    will work after i converted it to utf-8
    the search function don't work :(
    utf-8 cause it to not work.
     
    someone100, Nov 3, 2008 IP
  11. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #11
    try to add a in the search script

    $_POST[q]=urldecode($_POST[q]);

    could help.
     
    happpy, Nov 3, 2008 IP
  12. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    happpy, where have you found "$_POST[q]" ????
    update : i have tried to upate the index page but still no result . i can type something in hebrew in the text search but get white page .
     
    someone100, Nov 3, 2008 IP
  13. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #13
    i found $_POST[q] because your form on the page submit that :)

    you get a white page when you search hebrew. i saw that too.
    it must be some other issue on the system,
    cause if UTF8 is taken wrong, it normally should at least return "NO RESULTS".

    so the script instantly crashes or does not even get executed.

    never saw this before.

    do you have "error_reporting();" turned off in the script?? if so, turn it on, and look what the script says then, when error_reporting is on DEBUG
     
    happpy, Nov 3, 2008 IP
  14. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    great idea !!!!!
    i have found it . i will chage and update.....
     
    someone100, Nov 3, 2008 IP
  15. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    ooops !!!! i have put error_reporting(E_ALL) but now it is too much errors :)
    what an i do ?


    now i have changed to : E_ERROR | E_WARNING | E_PARSE
    and error is :
    "
    Warning: Cannot modify header information - headers already sent by (output started at /home/avimam/public_html/smgames/templates/arcadeblue-2/template_functions.php:1) in /home/avimam/public_html/smgames/index.php on line 150"
     
    someone100, Nov 3, 2008 IP