Character encoding issue for £ sign

Discussion in 'PHP' started by frobak, Aug 10, 2010.

  1. #1
    Hi

    On a clients recruitment website, i am displaying the details of a vacancy which includes the salary preceeded by a pound sign. When the job details are entered into the mysql database through a html/php form, it changes the £ sign to £, which is no problem, as when i display the variable on the job detail page it displays the £ sign, which is cool.

    code here:
    					<?php
    						include("includes/db_connect.inc.php");
    						
    						$query = "Select * FROM vacancies ORDER BY date_added DESC";
    						
    						$result=mysql_query($query);
    
    						$num=mysql_numrows($result);
    
    						mysql_close();
    
    						$i=0;
    						while ($i < $num) {
    
    						$vacancy_id = mysql_result($result,$i,'vacancy_id');
    						$job_title = mysql_result($result,$i,'job_title');
    						$salary = mysql_result($result,$i,'salary');
    						$location = mysql_result($result,$i,'location');
    						$terms = mysql_result($result,$i,'terms');
    						
    						echo "	
    									<div class='briefdesc'>
    										<div class='desc_title'>
    											<p class='title_text'>$job_title</p>
    											<p class='title_text'>$terms</p>
    										</div>
    										<div class='desc_details'>
    											<table>
    												<tr>
    													<td class='detail_text'>Location:
    													</td>
    													<td class='detail_text'>$location
    													</td>
    												</tr>
    												<tr>
    													<td class='detail_text'>Salary:
    													</td>
    													<td class='detail_text'>$salary
    													</td>
    												</tr>
    												<tr>
    													<td class='detail_text'>Contract:
    													</td>
    													<td class='detail_text'>$terms
    													</td>
    												</tr>
    											</table>
    										</div>
    										<div class='desc_more'>
    											<a class='viewvacbut' href='view-vacancy.php?vacancy_id=$vacancy_id'><img class='no_marg' src='images/more.png' /></a>
    										</div>
    									</div>
    							";
    						$i++;
    						}
    					?>
    PHP:
    BUT

    I am also displaying this job on the homepage as a job of the week, inside a joomla template. The job of the week is not managed inside of joomla, it is just displayed dynamically through my own scripts. But instead of displaying the £ sign for the salary variable, it is showing £.

    code here:
    							<?php
    								include("includes/db_connect.inc.php");
    								
    								$query="SELECT * FROM vacancies WHERE jotw = 'yes'";
    								
    								$result=mysql_query($query);
    
    								$num=mysql_numrows($result);
    
    								mysql_close();
    
    								$i=0;
    								while ($i < $num) {
    								
    								$vacancy_id 	= mysql_result($result,$i,'vacancy_id');
    								$job_title 		= mysql_result($result,$i,'job_title');
    								$salary 		= mysql_result($result,$i,'salary');
    								$location 		= mysql_result($result,$i,'location');
    								$terms 			= mysql_result($result,$i,'terms');
    								$desc1 			= mysql_result($result,$i,'desc1');
    								$limit_desc1 	= substr($desc1,0,200);								
    								
    								echo "<table id='jotw_table'>
    										<tr>
    											<td class='jotw_title'>$job_title
    											</td>
    										</tr>
    										<tr>
    											<td class='jotw_title'>$salary
    											</td>
    										</tr>
    										<tr>
    											<td class='jotw_title'>$location
    											</td>
    										</tr>
    										<tr>
    											<td class='jotw_title'>$terms
    											</td>
    										</tr>
    										<tr>
    											<td class='jotw_desc'>$limit_desc1...
    											</td>
    										</tr>
    										<tr>
    											<td><a href='../view-vacancy.php?vacancy_id=$vacancy_id'><img class='no_marg' src='../images/more.png'></a>
    											</td>
    										</tr>
    									  </table>
    								
    								";
    								$i++;
    								}
    							?>
    PHP:
    The 2 scripts displaying the vacancy details are very similar, so i am completely stumped as to why it is displaying differently.

    All the web pages are encoded utf-8, including the index.php file within the joomla template.

    Any help is muchly appreciated.

    cheers
     
    frobak, Aug 10, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    £ = html code &#163;
     
    MyVodaFone, Aug 10, 2010 IP
  3. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    yep i know that. But if its displaying ok for the first script, why not the second?
     
    frobak, Aug 10, 2010 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Or &pound;, which is probably easier to remember.

    Anyway, compare the charsets used on both sites. You might want to take a look at utf8_encode()/utf8_decode().
     
    nico_swd, Aug 10, 2010 IP
  5. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5
    all chatsets are utf-8? and the scripts are on the same site

    as the client is enetering this data into a form, they are using the £ sign, so i will need to figure out why it is displaying correctly through 1 script and not the other?
     
    frobak, Aug 10, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    How are you displaying "job of the week" is it an iframe or something ?

    This is the only problem right ?
     
    MyVodaFone, Aug 10, 2010 IP
  7. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #7
    yes job of the week is the only problem.

    No it is not in an iframe, it is inside a joomla template, but not managed from within joomla.
     
    frobak, Aug 10, 2010 IP
  8. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #8
    Assuming its salary you could do this, it will decode $salary £ - £ regardless

    <tr>
                                                <td class='jotw_title'>utf8_decode($salary);
                                                </td>
                                            </tr>
    Code (markup):
     
    MyVodaFone, Aug 10, 2010 IP
    frobak likes this.
  9. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #9
    ok, so how would i use this as you have stated? as this is a dynamically displayed table

    i added what you said but it just outputs - utf8_decode(£22,000);

    how do i drop out of php to get this to work?
     
    frobak, Aug 10, 2010 IP
  10. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #10
    ah solved it now.

    cheers MyVodaFone, i just decoded the variable before displaying.

    cheers. Been working on this since this morning. bummer!
     
    frobak, Aug 10, 2010 IP