Привет всем!
Купил прикольный скрипт микроблога на кодконьене, так вот проблемка в нем….
При добавлении сообщения на сайт (поста), вместо кавычек, на сайте показывается » & quot;»…
по принципу "новичкам везет" - перв
Почему и как исправить?
Вот файл настроек, может подскажите где поправить это:
<?php
/*
* Function to show an Alert type Message Box
*
* @param string $message The Alert Message
* @param string $icon The Font Awesome Icon
* @param string $type The CSS style to apply
* @return string The Alert Box
*/
function alertBox($message, $icon = "", $type = "") {
return "<div class="alertMsg $type"><span>$icon</span> $message <a class="alert-close" href="#">x</a></div>";
}
/*
* Function to convert a UNIX Timestamp to a Time Ago
*
* @param string $datetime The Unix Timestamp
*/
function timeago($date) {
if (empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if (empty($unix_date)) {
return "";
}
// is it future date or past date
if ($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if ($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
}
/*
* Function to filter profanity words
* Replace profanity word with FontAwesome asterisks
*
* @param string $text The text to be filtered
* @array $filterWords The profanity to filter for
* @variable $filterCount The character length of the profanity word
* @return string The filtered text
*/
function filterwords($text) {
$filterWords = array(
'arsehole','asshole','blow job','blow-job','blowjob','cum','cunt','dick','fuck','fucker',
'fuckface','fuckhead','fuckin','fucking','mother fucker','motherfucker','penis','pussy',
'titty fuck','titty-fuck','tittyfuck','twat','motherfuckin','nigger','ass','shit','shitty'
);
$filterCount = sizeof($filterWords);
for($i = 0; $i < $filterCount; $i++) {
$text = preg_replace('/b'.preg_quote($filterWords[$i]).'b/ie',"str_repeat('<i class="fa fa-asterisk filtered"></i>',strlen('$0'))",$text);
}
return $text;
}
/*
* Function to ellipse-ify text to a specific length
*
* @param string $text The text to be ellipsified
* @param int $max The maximum number of characters (to the word) that should be allowed
* @param string $append The text to append to $text
* @return string The shortened text
*/
function ellipsis($text, $max = '', $append = '…') {
if (strlen($text) <= $max) return $text;
$replacements = array(
'|<br /><br />|' => ' ',
'| |' => ' ',
'|’|' => ''',
'|‘|' => ''',
'|“|' => '"',
'|”|' => '"',
);
$patterns = array_keys($replacements);
$replacements = array_values($replacements);
// Convert double newlines to spaces.
$text = preg_replace($patterns, $replacements, $text);
// Remove any HTML. We only want text.
$text = strip_tags($text);
$out = substr($text, 0, $max);
if (strpos($text, ' ') === false) return $out.$append;
return preg_replace('/(W)&(W)/', '$1&$2', (preg_replace('/W+$/', ' ', preg_replace('/w+$/', '', $out)))).$append;
}
/*
* Function to Encrypt sensitive data for storing in the database
*
* @param string $value The text to be encrypted
* @param $encodeKey The Key to use in the encryption
* @return The encrypted text
*/
function encryptIt($value) {
// The encodeKey MUST match the decodeKey
$encodeKey = '0z%E4!3I1C#5y@9&qTx@swGn@78ePqViI1C#5y@';
$encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($encodeKey), $value, MCRYPT_MODE_CBC, md5(md5($encodeKey))));
return($encoded);
}
/*
* Function to decrypt sensitive data from the database for displaying
*
* @param string $value The text to be decrypted
* @param $decodeKey The Key to use for decryption
* @return The decrypted text
*/
function decryptIt($value) {
// The decodeKey MUST match the encodeKey
$decodeKey = '0z%E4!3I1C#5y@9&qTx@swGn@78ePqViI1C#5y@';
$decoded = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($decodeKey), base64_decode($value), MCRYPT_MODE_CBC, md5(md5($decodeKey))), "");
return($decoded);
}
/*
* Function to strip slashes for displaying database content
*
* @param string $value The string to be stripped
* @return The stripped text
*/
function clean($value) {
$str = str_replace('\', '', $value);
return $str;
}
?>
Заранее спасибо!
Не только в комментариях. В заголовках вопросов тоже.
Также иногда «ломаются» ссылки. Пару раз за последнюю неделю приходилось ставить лишний символ в текст якоря, разрывать его дефисом или точкой, и тогда повешенная на тот текст ссылка отрабатывала нормально. И ещё вчера-позавчера видел вместо пробела.
По-видимому, что-то поменяли в коде сайта. Теперь в каких-то случаях идёт автозамена символа (кавычки, пробела, слэша?) на его код там, где это не нужно — а обратного преобразования нет (подсказывает Капитан Очевидность). А вообще это не наше дело. Нам за диагностику и решение проблем не платят, даже копейку репутации не дадут. Вот и не стоит забивать мозги и тратить время. Голова отдохнёт, но время-то не вернётся. И от наших обсуждений не изменится ничего. Отправил пару скриншотов в техподдержку, пускай думают.
$search = array (
"'"'i",
"'&'i",
"'>'i",
"'<'i",
"'''i"
);
$replace = array (
""",
"&",
">",
"<",
"'"
);
Следующая регулярка. При обработке символов заменяет их нормально, но при выводе вместо » выводит на страницу " — то есть браузер не обработал спецсимвол " и вывел его как есть. Остальные выводит как нужно. Как исправить эту проблему?
I have a PC running Windows 7. Surfing the web, I see plenty of normal quotation marks («, ‘) around. But occasionally, I’ll see it written out as its HTML entity like this: "
. I frequently see it on well-designed, big budget websites whose designers should know what they’re doing, like IGN or CNN.
I’m curious as to why I’m seeing this, and if there’s something wrong with my browser or computer. But my real question is this: is there a way to prevent special characters from appearing as HTML entities when other people, especially with older systems, view my website?
Generally speaking, what kind of code could cause this problem to arise, and how can it be prevented?
Вопрос:
<input type="text" autocomplete="off" class="Autocomlete1" name="test">
$('.Autocomlete1').typeahead({
ajax: {
url: './test.php?log=test',
triggerLength: 1
},
updater: function(item) {
return item;
},
onSelect: function(item) {
return item;
}
});
После автокоманды в input
мы получим следующее значение – Text " TextTextText "
(строка базы данных имеет значение), но требуется выход Text " TextTextText "
Для замены "
на "
я хочу сделать:
onSelect: function(item) {
var text = item.text;
var text = text.replace(/"/g, '"');
$('.Autocomlete1').val(text);
return item;
}
Но это не работает…
Скажите, пожалуйста, как правильно заменить "
на кавычки?
Лучший ответ:
если не работает var text = text.replace(/"/g, '\"');
проверьте другие строки, потому что это сработало для меня.
Ответ №1
“также нужен escape-символ перед строкой write ‘”
var text = text.replace(/"/g, '\"');