General Question

Vincentt's avatar

How can I create a special character in PHP from a variable?

Asked by Vincentt (8094points) November 16th, 2007

Hi,

In PHP, if I have

$var = ‘AA’;

I want to be able to achieve the same result as I would have when doing

echo ”\xAA”;

Which would output ª
I tried doing

echo ”\x$var”;

But that only literally outputted the string (\xAA), instead of ª what I wanted. Any ideas how I can do it?

Thanks.

Observing members: 0 Composing members: 0

3 Answers

sferik's avatar

After playing around with PHP’s eval function for a while, I’ve concluding that doing what you’re trying to do is impossible.

The problem is that ’\xAA’ is a single character. It can’t be split in to parts in the same way that the Unicode character ‘a’ can’t be split into parts.

Vincentt's avatar

OK… Then do you know ig there is any way to create all characters possible with the following regex?

\x[0–9A-Fa-f]{1,2}

Without, of course, just taking all characters?

Vincentt's avatar

Never mind, I found out I can’t do what I wanted to do because normal letters and numbers also have their equivalents, and since I was replacing the special characters with their code that would continue forever…

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther