Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Character Encoding And Rewrite?


im having a real problem with character encoding and php i aware that php has some problems with character encoding but i dont really understand them

whats got me even more stumped is that when i was developing the same thing on my pc i never had this problem im now on a mac
whats more the problem only seems to happen when using the rewrite rule in the htaccess?

basically if i have an file index.html and it is
<?php
      echo "£";
?>

it echos a £ sign fine

if however i use an htaccess file to redirect any request to another file lets say invoke.html and it has the same thing it outputs £

i know for this example i should just echo &pound;
but this isnt exactly what im trying to do
this is just the simpliest example of the problem
what im actually doing is fopen fread a file then using strpos to find any £ symbols

the £ symbols in the file are just £ symbols
if i echo the read file contents they output as just £ symbols

however if i put "£" in as the needle for strpos it goes in as £ and therefore doesnt find it in the haystack.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Help On Character Encoding
I have a string in windows-1256 character set. But i would like to change from this chracter set to utf-8. (actually it is for to display arabic text). I am using in my whole site utf-8.
Any help highly appreciated.

Character Encoding In PHP & GD2?
I have been working on a dynamic image in GD2 which acts as a chatbox in a forum signature. It all seems to be working pretty well, but I have come across a bug (of sorts): if the user were to enter characters such as '¬_¬' the result in the image is shown as 'Ž_Ž'.

Is there any way that, using PHP, I can change this so that is actually understands the characters and would print '¬_¬'.?

Character Encoding
I'm working on a site for my brothers friend and it has a commentary system.
The commentaries get added by calling a Javascript which updates the current page and then call a PHP script to store the comment in a mySQL database.
My problem is at if the user uses any kind of special chars like the danish chars: æ, ø and å then the PHP script will just die on them. It will store the message until the chars and then stop.

I've tried running an escape () in the javascript on the txt i'm sending, and i've tried using CONVERT ('string' USING utf8) in the SQL query. The entire site is encoded in UTF-8, and so is the database but the user might type in ISO-8859-1 (?).

Somewhere else on the site i have a fileupload, here the page calls the upload script directly and it has no problems storing special chars in the database, so i'm thinking the problem might be a combination of the Javascript and PHP.

I'm hoping someone has an idea to what might be wrong. Code:

Detect Character Encoding?
My Problem is I want to build my own small web interface. works fine with imap_ functions so far. But now i got problems with Mails coming from MS Outlook - they are UTF-7 or UTF-8 encoded.

I don't know how to find out how they are encoded?

Second Problem: Got a character Sequence in the subject looking like that:

Ihre Anfrage: =?iso-8859-1?Q?minpoll=20timelimit=20wie=20gro=DF=3F?=

Don't know what to do with that.

Perhaps someone could drop some info on encoding.

Character Encoding Issues
I have built a CMS for a client. They client is copy pasting characters from Microsoft Word into the CMS and saving. When the CMS content is later displayed, several of the characters are shown as wier junk characters like: — or ’.

I fixed this at one level by converting the MySQL database to UTF8. This fixed it insofar as my computer is now diaplaying those characters properly but apparently some other computers are not. Some other computers are still showing wierd characters.

Does anyone know what the problem thus might still be? Are some client machines missing the fontmaps to express those characters? Or, are they not understanding to display that text as UTF8 perhaps?

Character Encoding Issues
When I use utf-8 encoding my page shows up fine. However, if I use
iso-8859-1 I get some funky characters that show up at the top of my page
where I am just calling "require_once." I am using a Win32/IIS/ISAPI/PHP5
installation, anyone have an idea of what's going on and how to resolve?

Character Encoding Problem - £ (pound) Sign
I have a simple PHP page that takes values from a form and puts them in a
database (MySQL).

The code is in a file test.php, which I have typed in at the bottom of
this post (please excuse any typos). This page is not a production page -
I created it just to try and solve the £ sign problem I am having.

When I put the pound sign (£) into the input box and submit the form,
what gets inserted into mysql is an A with a ^ on top, followed by the
pound sign. I notice that the request URI shows the £ sign as %C2%A3. If
I run the query manually in php (i.e. mysql_query("INSERT INTO test
VALUES('£')") ) then it is fine. (The problem occurs with both GET and
POST)

I have read up a bit about it and I believe that the problem is that one
part of the system uses UTF-8 while the other part uses ISO-8859-1. The
database is ISO-8859-1 (latin1).

Using phpmyadmin, I can put a £ sign into the database with no problem,
so I know that there must be a solution to this issue within PHP, but I
have no idea what it is!

test.php:

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db("test");
mysql_query("INSERT INTO test VALUES('".$_REQUEST['testpound']."')");
?>
<HTML>
<BODY>
<form action="test.php">
<input name="testpound">
<input type="submit">
</form>
</body>
</html>

PHP + MySQL (+AJAX) Character Encoding Problem
i'm developing a site using php + mysql and javascript (ajax techniques). My problem is, that some characters like &#321; arent displayed correctly. Their codes are shown, not the symbols themselves.

MySQL encoding is UTF-8, the encoding of the webpages is ISO-8859-1.

What am i doing wrong?

Find Out Encoding Of A File With Php, And Convert It To UTF-8 Encoding
In my script I need to find out the encoding of a file and in case it
is not of the kind UTF-8 I need to convert it to that format.

URL Rewrite In PHP
I know that mod-rewrite is really the way to go for rewriting URLs and such (when using Apache), but... I rent webspace on a shared server and cannot directly modify Apache config files. This leaves me with two options:

1). Using .htaccess files (which I have heard have a significant performance impact when used for mod_rewrite).

2). Handle URL rewriting through PHP itself (though this would only be a pseudo rewrite). Something similar to http://www.alistapart.com/stories/succeed/

I have concerns with both: on one hand, performance; on the other hand, security.

Any suggestions or feedback on which approach would be ideal?

Rewrite The Url
I'm using a get variable to enable a guest login via a hyperlink. Once
I've used it, is there a simple way of rewriting the url to remove ther
get details?

Mod-rewrite
I am rather new to mod rewrite an trying to pass on a parameter by mod-rewritten url, but somehow I can´t get it to work:This is my .htaccess:

RewriteEngine On
RewriteRule ^sub/(.*) /sub/index.php?c=$1

What I want to do is that every word in the folder "sub" would be taken as parameter "c" being processed by the index.php in the folde "sub". But somehow I keep getting an internal error while the script itself works. So if I type in: domain.tld/sub/record5 it would not work while on the other hand when I type in domain.tld/sub/index.php?c=record5 it works.

Mod Rewrite
How the heck do I get mod rewrite to add extensions to any file?

RewriteRule ^(.*)$ $1.php [nc]

To me that should find any group of characters(such as any path) and then
add the .php to the end? But this doesn't work and gives me a server error.
If I remove the $ in front of the 1 then it does but ofcourse all my links
end up as 1.php

I can also do something like

RewriteRule ^3(.*)$ $1.php [nc]

and all my links will be redirected to 3---.php

What I want is to take

[url] into [url].php

(without query string and or other special chars such as ([^&?]&) or [QSA])

I just can't understand why the following does not work ;/

RewriteRule ^(.*)$ $1.php [nc]

$1 should be whatever is matched by (.*)? (which should be the whole url?)
In any case I can't see how its an error?

Mod-rewrite
I am stuck with a problem and hope that probably someone of you can help me out on that one: I did a mod rewrite on a search engine of mine. This is the mod rewrite code:

RewriteRule ^(([^.]+)|([^.]+)/([^.]+)(.html)?)$ index.php?search=$1

Now the rewrite works fine as long as the search term is only "abc" or "a-bc", but it doesn´t work for search terms that contain a dot like "a.bc". Does anyone know how I change the rewriterule that way, that it would work with dots as well?

How To Rewrite Url In Php
how i am rewrite url in php. i hav no idea about url rewritting. i am createing adynamic site and my url look like http://localhost/adminajax/home1.php?sub_cat_id=1
now i need url look like this http://localhost/adminajax/home1.php/animation automation.

Url Rewrite
how to make new rule in url rewrite

http://localhost/outsourcing/index.php to http://outsourcing

and
http://localhost/outsourcing/index.php?sub_cat_id=94  to http://outsourcing/animation

Mod Rewrite
I have a link www.example.com/folder/ but when people visit this i want it to go to www.example.com/folder/index.php because then it will log the page visit. Any ideas using mod rewrite i can get /folder/ to redirect to /folder/index.php ?

URL Rewrite
I want to show one URL at browser and content of different URL.

Like user can see the URL at address bar like:

href="http://localhost/test/home/

or

http://localhost/test/tech/php/

but content of page will be

http://localhost/test/index.php

The URL of the address bar will never change to
http://localhost/test/index.php

Mod Rewrite URL Problems
I created my .htaccess code and its working on my server, the only thing is my urls all have plus signs as spaces.. exp.

http://www.somesite.com/How+to+find+this.html

How do I change this to - signs?

I know this is a php topic, but hold on I'll explain...

here is my .htaccess coding which is working..

RewriteEngine on

RewriteRule ^(.+)Article([0-9]+).html(/)?$ articleDetail.php?id=$2&title=$1

RewriteRule ^(.+).html(/)?$ $1.php

and here is my php code for the urls

<a href="<?php echo stripslashes(urlencode($title));?>+Article<?php echo $id?>.html"><?php echo stripslashes($title);?>...</a>

I'm fairly sure its nothing to do with the htaccess coding... but the php coding.. which I had a friend help me with.. but he doesnt know how to fix it..

Sessions With Mod Rewrite
after building my last project and everything working fine, we decided we wanted to use mod_rewrite for better SEO. The rewrite rules are working as expected but there is one significant problem.

Suddenly the pages accessed with rewrite lose their sessions. I am guessing that I am missing some kind of header. Also when I click view source on the browser, Notepad comes out blank on the pages using rewrite. And sometimes the pages open a 'save as' dialog box. The output html does have the following head tags:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

I thought maybe this was a problem with the local server so I uploaded the site onto the live server and I have the same problem there.

I am using the following
Smarty 2.5
apache 1.3.27
slackware 8.0
php 4.3.2

My best guess is that I might need a header(); so that the browser fully understands what it is accepting. I just don't know which, I have trouble with headers sometimes.

URL Rewrite + Htaccess
I have a domain, and i want every query string
redirected to index.php?
so domain.com/foo/bar would actually be domain.com/index.php?/foo/bar
Then i want to be able to say in index.php,
if QUERY_STRING == foo, do this etc.
(How) can i do this with htaccess?

URL Rewrite + PHPSESSID?
I use session.use_trans_sid On to have the PHPSESSID attached to the URL. I do not start the session when the Googlebot is detected, so far Googlebot has begun to look a bit more deeper down other than just the home page.

I am trying to turn all the pages into static URL using rewriterules. Only problem is I still want the users to use the site without the cookie turned on by using the PHPSESSID. With the rewritten URL, use_trans_sid still attaches the sid to the URL, eg. I have tried a rewrite rule as:

RewriteRule ^test0/([^/]+).html?(PHPSESSID=[a-f0-9]+)$ /test.php?ID=$1&$2

It does not really work, it looks like rewriterule ignores "?" in the URL.

Url Rewrite On A GET Form?
is it possible to control the URL sent from a web form of the GET type? write now I have my little search form, user types word(s) hits search, but instead of "http://domain.com/search.php?words=word1+word2" I'd like to take advantage of my htaccess and rewrite to search/word1+word2.

I can do this easy in htaccess, but how do i get the FORM to send the url THIS way?

anyone with experience in controlling form urls?

Rewrite File Line
I am trying to write a portion of the script that will replace a line with a new one in a text file. I figured fputs would do the trick, but I tried opening the file with fopen with the mode r, r+, and w+ and they don't seem to do the trick. r will only read, r+ is supposed to read and write, but instead it just reads (nothing new was inserted when I tried it), and w+ erases the file then inserts the new information.

The way the script works, it will search for the proper line using a while loop, once found, it will take the information and modify it slightly, then it's supposed to overwrite the new line over the old one, afterall, the pointer have not changed it's position since it found the correct line.

I don't want to replace an entire file because the script will do more work, just one frigging line in the same position.

Virtual Subdomains Using Mod Rewrite
I am trying to show virtual subdomains using mod rewrite. For example: User will see sub.domain.com where the actual URL is domain.com/sub I need script which can do this. Can anyone help me?

Session.use_trans_sid And Mod Rewrite
can session.use_trans_sid be used with mod rewrite? I had a script that worked without cookies because I had enabled session.use_trans_sid. I have since utilized mod rewrite successfully, but the script no longer functions without cookies. The benefits of mod rewrite far outweigh the benifits of having the script work without cookies, but I'm wondering for my own knowledge if it is possible to have them work together.

Rewrite And Page Anchors
The following is my htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/(.*) content.php?category=$1&urlrewrite=$2 [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

What I'm trying to figure out is how to handle page anchors, for example- content.php?category=all&urlrewrite=short#middlepage. How can I go about this? What modifications to the htaccess file?

Wordpress PHP Rewrite To Email Campaign
I am trying to create a wordpress plugin where it does 2 things, because its 2 parts to a script I am trying to create a redirect.php file where it does:

1. rewrites to a separate form in the background -> email form
2. then rewrites back to the wordpress comments/sql

second part:

1. rewrites to a seperate form in the background -> email form
2. rewrites to another form -> another email form
3. then rewrites back to the wordpress comments/sql

The first part is the most important, the second part is not of an issue.

I have a script that does the first part, which it rewrites to a database (so it can provide me some stats) and then rewrites the form. the form method is redirected to the PHP file which brings the user to a blank page while it rewrites to my database and then once its done it rewrites the form attributes and processes the form.

the issue that I have is I do not know how to incorporate it within wordpress as a "plugin" and I also do not want to mess any of my other plugins up any ideas?

Use Of Mod Rewrite In Apache2 Breaks PHP $ REQUEST Parsing
Whilst testing a new site layout, with dynamic URLs written to be human-friendly (and mod_rewrite used in Apache to turn those urls back into GET variables), I found that any 'directory' containing an ampersand (`&') or a plus (`+') just would not open within the edit pages....

URL Encoding
In one of my PHP applications, I generate a dynamic link to another page. The parameter list contains a few variables with some special characters, so as expected, I use urlencode() to encode the parameters before plopping them into the URL.

For some strange reason, the link doesn't work - I get a "page cannot be displayed" error in IE 6. NS 6 starts to load it, then just stops. Oddly enough, if I go into the location bar (under IE at least), and delete one (1) character, any character from this one particular parameter (search_expr), the page loads fine (albeit with a messed up parameter). Code:

URL Encoding
Can anyone point me in the direction of a tutorial on URL encoding? I am creating a website and i want to use 1 page which contains the layout, then seperate pages with the content. i would do it something similar to this:

http://website.com/index.php?page=links

Then that would just call up a .inc page specified in the page= variable and display it on index.php.

Php Encoding
i was wondering, which is a good-freeware php enconding alternative?
Im running the apache server on a windows platform.

Encoding
I have a problem. How can I transform this xml:
$xml="<name>Niccol&#xF2;</name>"
to this
$xml="<name>Niccolò</name>"

I recive by CURL from a site this xml:

<?xml version="1.0">
<name>Niccol&#xF2;</name>

but, for some reasons, I want:

<?xml version="1.0">
<name>Niccolò</name>


Which Encoding?
Not really a PHP question, but i've got an app that sends me this type of
encoding:

á (&aacute;) translates to %C3%A1
ñ (&ntilde;) translates to %C3%B1

i've tried several decodings with PHP without any good result.
Anyone knows which type of encoding is this and which function to use in
order to decode it with PHP?

Encoding
my website is parsing 4 external xml files (rss feeds) and writes them in a mysql database. my problem is that 2 of the xml files are encoded in utf-8 and 2 of them are windows 1250. when i need to retrieve the data from the database and display it on my site (which is utf-8) i have a problem with special characters that are encoded in windows 1250. I need all the data in my database to be encoded in one way. how to do that ? or is there another way?

Chinese Encoding
I have a forum mainly in Chinese character. There are some characters which cannot be shown correctly and turn into "& #22175" ... does anyone know how to fix this?

Email Encoding
I'm using the code below to send emails right now. Its is secure?

Low-end PHP Encoding For Windows
FYI, BadBlue added a built-in PHP encoding capability to the enterprise version of their Windows web server. The personal edition of the server is a free download and is a quick easy way to get PHP running: http://badblue.com/helpphps.htm .

Encoding Problem
I have a dom tree representing the content of a html document. In the xml I
use &#x20AC; as the euro sign. I think I need to do this to be able to use
xsl transformations. After the xsl transformation I use a small SAX
parser. But my &#x20AC; gets converted to: â,¬50.
I've tried passing xml_parser_create() 'UTF-8' and '' (hint from php.net)
but it only makes things worse ( ? or squares are displayed ).
How do i have to encode characters to be able to pass them to SAX. Is there
a build in function or do I use str_replace()?

Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
The soul would have no rainbow had the eyes no tears.

GB2312 Encoding In PHP
I have language text stored as variables in text files, which are
'included' by my PHP scripts (is there a better way?). However, I seem
to have a problem with the simplified chinese GB2312 encoding format.

I thought that most foreign encoding mechanisms would avoid the use of
the quotation mark - however, I saved something out as GB2312 and now
effectively get parse errors (due to premature quotes which appear to
form parts of the Chinese characters themselves).

A few other websites I tested though don't seem to have a problem
sending me mail in GB2312 though ... so they must have somehow managed.

Locale And Different Encoding
I have a simple question about locale and PHP5.

I'm using polish characters but I encode them in UTF-8.
I was sorting an array with usort($array, 'strcoll'); but I've entred a
problem.
I was sorting arrays this way:

setlocale(LC_ALL, 'pl_PL.utf8');
usort($array, 'strcoll');

but it turned out to be completely wrong...

I've started to test various encodings on various OS and ended with
this sample PHP script
that sorts UTF-8 encoded array on both Linux and Windows with locale
encoding set to ISO-8859-2:

<? // file encoding is UTF-8
$array = array('Aea', 'Eaz', 'Eaz', 'Eaz', 'Aea', 'Aeas');

var_dump(mb_detect_encoding($array[1])); // shows UTF-8 - OK

// set locale encoding ISO-8859-2
// pl_PL for Linux
// polish_Poland.28592 for Windows
if (PHP_OS == 'WINNT') {
setlocale(LC_ALL, 'polish_Poland.28592');
} else {
setlocale(LC_ALL, 'pl_PL');
}

// sort
usort($array, 'strcoll');

// works OK on both Linux and Windows
var_dump($array);
?>

how come it works on both Linux Gentoo PHP 5.1.1 and
Windows NT PHP 5.1.4?

the contents of $array contents are encoded in UTF-8, but encoding is
set to ISO-8859-2 (via setlocale)

Php Script Encoding
this is my first "topic" on Google Groups.

I'm looking for a solution for 4 days, without results.

So... my apache is serving pages in UTF-8 but my php scripts are writed
(I'm speaking about strings) in ISO-8859-1.

How can I say at apache how to interpret my scripts in a different
charset?

I don't want to change every "è" with "&egrave;"
I think that it should be a simple configuration in the .conf or in the
..ini but... nothig found about.

SoapVar And Encoding
what's going on with the following (I'm working in non-WSDL mode).
Basically, I need the following in the SOAP request body:

<ns6:create>
...
<property>
<name>Property 1</name>
<value>Test Value 1</value>
</property>
<property>
<name>Property 2</name>
<value>Test Value 2</value>
</property>
</ns6:create>

So I've created a class called Create that has the required members,
and stores the property elements (which are instances of a class called
NamedValue) in an array:

class NamedValue {
public $name;
public $value;

public function __construct($name, $value) { ... }
}

class Create {
public $id;
public $parent;
public $type;
public $property;

public function __construct(...) {
...
$property = array(
new NamedValue("Property 1", "Test Value 1"),
new NamedValue("Property 2", "Test Value 2")
);
}
}

Euc-kr Encoding Problem
I have a dom tree representing the content of a html document.
I use character-set as the euc-kr sign.

Can I use a <?xml encoding="euc-kr" ?>
This source don't work.

How Can I use character-set as the euc-kr ?

Encoding/decoding A Variable
Is there a function that will temporarily encode a variable (say, for passing through a URL), and another that would decode the same?

SOAP And Accept-Encoding
I'm trying to make a SOAP request, and enable compression in
the response (by sending the Accept-Encoding header). To do this, I'm
sending 'compression' =SOAP_COMPRESSION_ACCEPT |
SOAP_COMPRESSION_GZIP in the SoapClient constructor's options.

But when I print the request headers, I don't see the Accept-Encoding
header. Am I doing something wrong?

I also tried SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 9 to
set the compression level, as I've seen in some examples.

I just downloaded and compiled php 5.2.1 with --enable-soap on Mac OS
10.4.9.

The full example is below:
$o_client = new SoapClient($wsdlURL, array(
'trace' =true,
'compression' =SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'login' =$login,
'password' =$password
));
$o_result = $o_client->acknowledge();
echo $o_client->__getLastRequestHeaders();

Zend Optimizer Encoding
I'm currently running into problems with Zend Optimized PHP code; or
more clear, a partner of mine asked me to adapt a script he bought which
is encoded this way.

Does anyone know if this can be done, or if there are any projects
trying to develop a free decoder/decompiler?

I know this might be a bit off-topic here, but I couldn't find a list
that seemed to fit better to me.

Domxml_new_doc - Can I Add Encoding Attribute?
I've got a question about adding encoding attribute to my DOM XML Document?

I'm from Poland and we use extended latin alphabet - I'd like to use
iso-8859-2 Polish charset

e.g.:
<?xml version="1.0" encoding="iso-8859-2"?>

is there such posibility in DOM XML?

Send Request With Encoding
Does anyone know if it allows to send request with specific encoding?

What i want to do is sending japanese as a parameter. But always gives
me an error "Invalid protocol "

$http_request = new Snoopy;
$str = mb_convert_encoding($this -mAddress,"UTF-8", "Shift_JIS");
$url = "http://www.myusite.jp/api/?v=1.1&q='"+$str+"'";

$http_request -fetch( $url );
if( !$http_request -error ){
}


Copyright © 2005-08 www.BigResource.com, All rights reserved