php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27864 Cannot create escaped character from multiple strings
Submitted: 2004-04-05 04:02 UTC Modified: 2004-04-05 06:46 UTC
From: rick at revenew dot nl Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.5 OS: Linux (Redhat 7.1/Debian Woody)
Private report: No CVE-ID: None
 [2004-04-05 04:02 UTC] rick at revenew dot nl
Description:
------------
Let's say I have a variable $var which contains 94.
Now I want to create the escaped character \x94 from this var. This seems to be impossible. I've tried all kinds different approaches. Simply concatenating two strings (single or double quoted). escaping the \x with \ sprintf()'ing  etc. It seems like it's impossible to create the escaped character from 2 (or more) parts.

At the moment I'm using a dirty fix to overcome this problem:

I have an array like this:

array(
		"\\x00"=>"\x00",
		"\\x01"=>"\x01",
		"\\x02"=>"\x02",
		"\\x03"=>"\x03",
                etc..
)

with this aray you can perform a strtr(); Which works around the problem.


Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-05 04:08 UTC] rick at revenew dot nl
BTW, I'm running into this problem while parsing html unicode strings like Δ to unicode characters in PDFlib.
The following section in the PDFlib manual describes the exact same problem (I think :) )with a resolution for the C++ binding of PDFlib:

Unicode in the C++ language binding. 
C++ users must be aware of a pitfall related to the compiler automatically converting literal strings to the C++ string type which is expected by the PDFlib API functions: this conversion supports embedded null characters
only if an explicit length parameter is supplied. For example, the following will not work since the string will be truncated at the first null character:

p.show("\x00\x41\x96\x7B\x8C\xEA"); // Wrong!

To fix this problem apply the string constructor with an explicit length parameter:

p.show(string("\x00\x41\x96\x7B\x8C\xEA", 6)); // Correct
 [2004-04-05 06:20 UTC] derick@php.net
What's wrong with the chr() function?
 [2004-04-05 06:46 UTC] rick at revenew dot nl
Hmm... Looks like i missed the obvious :) i was feeding chr() hexadecimal numbers in my tests, not decimal numbers...
Problem is solved now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Aug 14 09:01:28 2024 UTC