Danilo
Danilo

Reputation: 2686

file_get_contents and encoding

i have an external webpage with some content like this:

<script>
str = "hello";
fun('\202' + str + '\203\303\287');
</script>

In my PHP page, I am trying to retrieve (a part of) the argument of fun() in the following way:

$html=file_get_contents("webpage.html");
$regex_pattern = "/fun\(\'(.*)\'(.*)\'(.*)\'\)/";
preg_match_all($regex_pattern,$html,$matches);

$p1=$matches[1][0];
$p2=$matches[3][0];

echo "p1: ".$p1.", length: ".strlen($p1)."<br>";

What I get is that $p1 is equal to \202 and the length is 4. However, I would like to retrieve the character associated to \202 (and the same for the sequence of characters represented by $p2).

I browsed past questions related to similar matters but I was not able to get it working with the proposed solutions.

Any hints?

Thanks

Upvotes: 1

Views: 260

Answers (1)

mcrumley
mcrumley

Reputation: 5700

stripcslashes($p1);
stripcslashes($p2);

From: http://www.php.net/manual/en/function.stripcslashes.php

string stripcslashes ( string $str )

Returns a string with backslashes stripped off. Recognizes C-like \n, \r ..., octal and hexadecimal representation.

Upvotes: 1

Related Questions