B
B
betal2011-09-18 14:03:41
PHP
betal, 2011-09-18 14:03:41

Encodings with exec and svn?

There is a simple code.

exec(' svn log /var/www/new/svn/ | head -n100 ',$str);<br/>
for ($i=0;isset($str[$i]);$i++){<br/>
echo $str[$i],'&lt;бр /&gt;';<br/>
}

But instead of Russian letters, characters like
?\208?\152?\208?\183?\208?\188?\208?\181?\208?\189?\208?\181?\208?\189?\208?\176 ?\209?\135?\208?\176?\209?\129?\209?\130?\209?\140 ?\209?\130?\208?\176?\208?\177?\208?\187?\208?\184?\209?\134

Tried experimenting with iconv but nothing worked.
For some, this may be a simple task, but I did not really find information on the Internet.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kakysha, 2011-09-18
@kakysha

Here, too, the guys are suffering, maybe something will help you: stackoverflow.com/questions/6065557/unicode-to-php-exec

L
LastDragon, 2011-09-18
@LastDragon

It is the iconv that cures it, for example, for WinXP:
$svn_message = iconv('CP866', 'UTF-8', $svn_message);
In addition, the data transmitted to the command must also be converted into the correct encoding.
A complete working example of getting the svn log (code for mantis):
pastebin.mozilla-russia.org/109216

B
betal, 2011-09-29
@betal

I figured it out myself ...
the code turned out to be very messy, because I don't remember how to work with regular expressions, but the point is to understand how the message is encoded. If anyone can tell me what the second parameter should be, I will be grateful.
$output = shell_exec("svn log --limit 25 /var/www/new/svn/");
$output = nl2br ($output);
$output = preg_replace("/\?\\\\(\d+)/e","aaabbbcccddd$1rrrtttyyyuuu",$output);
$output = str_replace ('aaabbbcccddd','&#',$output);
$output = str_replace ('rrrtttyyyuuu',';',$output);
$output = html_entity_decode($output,ENT_NOQUOTES,"cp1252");
echo $output;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question