Olga Pshenichnikova
Olga Pshenichnikova

Reputation: 1581

PHP string encode

I have some site written on php5 using most ancient CodeIgniter version.
I have config:

$config['charset'] = 'windows-1251';

At some place, I have 2 string values.

  1. $this->uri->segment(2)
  2. "{shortname}" . ".html"

I want compare them, and do something if they are equals.
But I get into hell...

Now, I have some code in some view:

<?=(strcmp($this->uri->segment(2), "{shortname}" . ".html") == 0) ?
        'test' :
        'notest' ?><br/>
<?=mb_detect_encoding($this->uri->segment(2))?><br/>
<?=mb_detect_encoding("{shortname}" . ".html")?><br/>
<?=base64_encode(mb_convert_encoding($this->uri->segment(2), 'UTF-8'))?><br/>
<?=base64_encode(mb_convert_encoding("{shortname}" . ".html", 'UTF-8'))?><br/>
<?=$this->uri->segment(2)?><br/>
<?="{shortname}" . ".html"?><br/>

As a result I have:

notest
ASCII
ASCII
cml6b2dyYWZpamEtdGlyYXpoaXJvdmFuaWUuaHRtbA==
e3Nob3J0bmFtZX0uaHRtbA==
rizografija-tirazhirovanie.html
rizografija-tirazhirovanie.html

How I need encode/decode/compare for it will work?

Upvotes: 0

Views: 71

Answers (1)

maximkou
maximkou

Reputation: 5332

base64_decode("e3Nob3J0bmFtZX0uaHRtbA==") = {shortname}.html

Your {shortname} placeholder is not replaced. I'm not use CodeIgniter, but maybe you like to use {$shortname} ? (inserts $shortname variable value)

Example:

echo strcmp($this->uri->segment(2), "$shortname.html") == 0) ? 'test' : 'notest';

Upvotes: 3

Related Questions