Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   Разное - Покупка, продажа, обмен (https://forum.antichat.xyz/forumdisplay.php?f=52)
-   -   Переписать функцию с JavaScript на PHP за $$$ (https://forum.antichat.xyz/showthread.php?t=92331)

ttt0z 18.11.2008 11:33

Переписать функцию с JavaScript на PHP за $$$
 
function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++) {
if (num.charCodeAt(i).toString(16).toUpperCase().leng th < 2) {
hex += "&#x0" + num.charCodeAt(i).toString(16).toUpperCase() + ";";
} else {
hex += "&#x" + num.charCodeAt(i).toString(16).toUpperCase() + ";";
}
}
return hex;
}

для проверки из слова hello должно получиться
&#x68;&#x65;&#x6C;&#x6C;&#x6F;

bombeg 18.11.2008 11:43

PHP код:

function encode($word)
{
  
$result '';
  for(
$i 0$size strlen($word);$i $size$i++)
  {
    
$result .= '&#x' strtoupper(bin2hex($word[$i])) . ';';
  }

  return 
$result;
}
echo 
encode('hello'); 


ttt0z 18.11.2008 12:10

bombeg спасибо можешь еще помочь с кодом:



надо что бы полоучилось примерно:
&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041

это Long UTF-8 Unicode encoding without semicolons
This is also useful against people who decode against strings like $tmp_string =~ s/.*\&#(\d+);.*/$1/;

TomskDiver 18.11.2008 12:13

получилось из чего? как я понимаю ты что-то для xss делаешь?

bombeg 18.11.2008 12:17

PHP код:

function encode($word)
{
  
$result '';
  for(
$i 0$size strlen($word);$i $size$i++)
  {
    
$result .= '&#000';
    
$result .= (ord($word[$i]) < 100) ? '0' .ord($word[$i]) : ord($word[$i]);
  }

  return 
$result;
}
echo 
encode("javascript:alert('XSS')"); 


ttt0z 18.11.2008 12:20

bombeg спасибо большое!

bombeg 18.11.2008 14:10

$1 :D


Время: 13:00