本文整理汇总了PHP中mb_check_encoding函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_check_encoding函数的具体用法?PHP mb_check_encoding怎么用?PHP mb_check_encoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_check_encoding函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: validation_default
private static function validation_default($val, $min_len = 0, $max_len = 60, $regex_opt = '')
{
if (!is_string($val)) {
// validation_exit('Invalid type', gettype($val));
return "";
}
if (strlen($val) < $min_len || strlen($val) > $max_len) {
validation_exit('Too long value', strlen($val));
return "";
}
// Only UTF-8 is supported.
// WARNING: This code assumes UTF-8 only script.
if (ini_get('default_charset') != 'UTF-8') {
// validation_exit('Only UTF-8 is supported', $val);
return "";
}
if (!mb_check_encoding($val, 'UTF-8')) {
// validation_exit('Invalid encoding', $val);
return "";
}
// Allow only alpha numeric and UTF-8.
// UTF-8 encoding:
// 0xxxxxxx
// 110yyyyx + 10xxxxxx
// 1110yyyy + 10yxxxxx + 10xxxxxx
// 11110yyy + 10yyxxxx + 10xxxxxx + 10xxxxxx
// Since validity of UTF-8 encoding is checked, simply allow \x80-\xFF.
if (!mb_ereg('\\A[0-9A-Za-z\\x80-\\xFF' . $regex_opt . ']*\\z', $val)) {
// validation_exit('Invalid char', $val);
}
return $val;
}
开发者ID:K-atc,项目名称:Kch,代码行数:32,代码来源:WAF.php
示例2: load
public function load($url = null)
{
if (is_null($url) && is_null($this->url)) {
throw new Exception('You must set url to load');
}
if (empty($url)) {
$url = $this->url;
}
curl_setopt($this->curl, CURLOPT_URL, $url);
$response = curl_exec($this->curl);
if (curl_errno($this->curl) !== 0) {
throw new \Exception('cURL error: ' . curl_error($this->curl));
}
$httpCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
throw new \Exception('cURL request returned HTTP code ' . $httpCode);
}
$headersLength = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headersLength);
$response = substr($response, $headersLength);
$this->url = curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL);
$this->host = parse_url($this->url, PHP_URL_HOST);
$headers = preg_split('/^\\s*$/m', trim($headers));
// get last headers, after all redirects
$this->headers = end($headers);
$this->html = $response;
$this->html = mb_check_encoding($this->html, 'UTF-8') ? $this->html : utf8_encode($this->html);
}
开发者ID:seshurajup,项目名称:phpEngineDetect,代码行数:28,代码来源:Curl.php
示例3: checkUtf8Encoding
/**
* Check for invalid UTF8 encoding and invalid byte .
*
* @param string $string Your string.
*
* @return boolean
*/
public static function checkUtf8Encoding($string)
{
if (!mb_check_encoding($string, 'UTF-8') || !$string == mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')) {
return false;
}
return true;
}
开发者ID:gjerokrsteski,项目名称:pimf-framework,代码行数:14,代码来源:Character.php
示例4: curl
/**
* Perform a cURL request
* @param string $url
*/
protected function curl($url)
{
if ($this->debug) {
echo 'cURL request: ' . $url . "\n";
}
$ch = curl_init($url);
curl_setopt_array($ch, array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => $this->curlFollowLocation, CURLOPT_MAXREDIRS => $this->curlMaxRedirects, CURLOPT_TIMEOUT => $this->curlTimeout, CURLOPT_USERAGENT => $this->curlUserAgent));
$response = curl_exec($ch);
if (curl_errno($ch) !== 0) {
throw new WappalyzerException('cURL error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
throw new WappalyzerException('cURL request returned HTTP code ' . $httpCode);
}
$result = new stdClass();
$result->url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$result->host = parse_url($result->url, PHP_URL_HOST);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$result->html = substr($response, $headerSize);
$result->html = mb_check_encoding($result->html, 'UTF-8') ? $result->html : utf8_encode($result->html);
$headers = trim(substr($response, 0, $headerSize));
$headers = preg_split('/^\\s*$/m', $headers);
$headers = end($headers);
$lines = array_slice(explode("\r\n", $headers), 1);
foreach ($lines as $line) {
if (strpos(trim($line), ': ') !== false) {
list($key, $value) = explode(': ', $line);
$result->headers[strtolower($key)] = $value;
}
}
return $result;
}
开发者ID:Ancodercff,项目名称:Wappalyzer,代码行数:37,代码来源:Wappalyzer.php
示例5: convertEncoding
/**
* Ensures the encoding of the passed string is set to UTF-8.
*
* @param string $str
* @return string utf-8 string
*/
protected function convertEncoding($str)
{
if (!mb_check_encoding($str, 'UTF-8')) {
return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
}
return $str;
}
开发者ID:surebert,项目名称:MailMimeParser,代码行数:13,代码来源:HeaderPart.php
示例6: prepare_content
protected function prepare_content($content)
{
$result = $content;
if (empty($result)) {
return '';
}
$encoding = null;
$xml_error = new libxml_errors_mgr();
$dom = new DOMDocument();
$dom->validateOnParse = false;
$dom->strictErrorChecking = false;
if ($dom->loadHTML($content)) {
$encoding = $dom->xmlEncoding;
}
if (empty($encoding)) {
$encoding = mb_detect_encoding($content, 'auto', true);
}
if (!empty($encoding) && !mb_check_encoding($content, 'UTF-8')) {
$result = mb_convert_encoding($content, 'UTF-8', $encoding);
}
// See if we can strip off body tag and anything outside of it.
foreach (array('body', 'html') as $tagname) {
$regex = str_replace('##', $tagname, "/<##[^>]*>(.+)<\\/##>/is");
if (preg_match($regex, $result, $matches)) {
$result = $matches[1];
break;
}
}
return $result;
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:30,代码来源:entities.class.php
示例7: sendText
/**
* Prepare new text message.
*
* If $unicode is not provided we will try to detect the
* message type. Otherwise set to TRUE if you require
* unicode characters.
*/
public function sendText($to, $from, $message, $unicode = null)
{
// Making sure strings are UTF-8 encoded
if (!is_numeric($from) && !mb_check_encoding($from, 'UTF-8')) {
trigger_error('$from needs to be a valid UTF-8 encoded string');
return false;
}
if (!mb_check_encoding($message, 'UTF-8')) {
trigger_error('$message needs to be a valid UTF-8 encoded string');
return false;
}
if ($unicode === null) {
$containsUnicode = max(array_map('ord', str_split($message))) > 127;
} else {
$containsUnicode = (bool) $unicode;
}
// Make sure $from is valid
$from = $this->validateOriginator($from);
// URL Encode
$sFrom = urlencode($from);
$sMessage = urlencode($message);
// Send away!
$hPost = ['from' => $sFrom, 'to' => $to, 'message' => $sMessage, 'type' => $containsUnicode ? 'unicode' : 'text'];
return $this->sendSmsRequest($hPost);
}
开发者ID:epinett,项目名称:CamooBulkSms,代码行数:32,代码来源:CamooSms.php
示例8: __construct
/**
* Class constructor.
*
* @param mixed $string
* @param string $encoding
* @throws \InvalidArgumentException
*/
public function __construct($string, $encoding = self::ENCODING)
{
if (is_null($string)) {
$string = 'null';
} elseif (is_bool($string)) {
$string = $string ? 'true' : 'false';
} elseif (is_int($string) || is_float($string)) {
$string = (string) $string;
} elseif (is_object($string)) {
if (!method_exists($string, '__toString')) {
throw new \InvalidArgumentException(sprintf('Object of class %s cannot be converted to String', get_class($string)));
}
$string = (string) $string;
} elseif (!is_string($string)) {
throw new \InvalidArgumentException('Cannot convert a variable of type ' . gettype($string) . ' to String');
}
if (!self::checkEncoding($encoding)) {
throw new \InvalidArgumentException('Unsupported encoding: ' . $encoding);
}
if (!mb_check_encoding($string, $encoding)) {
throw new \InvalidArgumentException('String is not encoded in ' . $encoding);
}
if ($encoding != self::ENCODING) {
$string = mb_convert_encoding($string, self::ENCODING, $encoding);
}
$string = \Normalizer::normalize($string);
$this->string = $string;
$this->length = mb_strlen($string, self::ENCODING);
}
开发者ID:e-ruiz,项目名称:brick,代码行数:36,代码来源:String.php
示例9: testParse
/**
* @param string|\Closure $input
* @param string|null $filename
* @param string|null $title
* @param (string|string[]|float)[][][] $jsonable
* @param (string|string[])[] $metadata
* @param string[] $logLevels
* @dataProvider dictionaryProvider
*/
public function testParse($input, string $filename = null, string $title = null, array $jsonable = null, array $metadata = null, array $logLevels = [])
{
$parser = new GenericDictionaryParser();
$parser->setLogger($this);
if ($input instanceof \Closure) {
$archive = $input();
$file = new \SplFileInfo($archive->filename);
$archive->close();
$dictionary = $parser->parse($file, $filename, $title);
} else {
$dictionary = $parser->parse($this->generateTempFileObject(mb_check_encoding($input, 'UTF-8') ? $this->stripIndents($input) : $input), $filename, $title);
}
array_walk_recursive($jsonable, (function (&$field) {
if (is_string($field)) {
$field = $this->stripIndents($field);
}
})->bindTo($this));
$this->assertEquals($jsonable, $dictionary->getWords());
array_walk_recursive($metadata, (function (string &$field) {
if (is_string($field)) {
$field = $this->stripIndents($field);
}
})->bindTo($this));
$this->assertEquals($metadata, $dictionary->getMetadata());
$this->assertEquals($logLevels, $this->logLevels);
}
开发者ID:esperecyan,项目名称:dictionary-php,代码行数:35,代码来源:GenericDictionaryParserTest.php
示例10: is_utf8
/**
* @param $identifier
*
* @return bool
*/
public static function is_utf8($identifier)
{
if (mb_check_encoding($identifier, 'UTF-8')) {
return true;
}
return false;
}
开发者ID:katymdc,项目名称:thermal-api,代码行数:12,代码来源:jsonp.php
示例11: isValidUTF8
/**
* Ckecks a string for valid UTF8 encoding
*
* @param $string
*
* @return bool
*/
public static function isValidUTF8($string)
{
if (function_exists("mb_check_encoding")) {
return mb_check_encoding($string, "UTF-8") ? TRUE : FALSE;
}
return preg_match("//u", $string) ? TRUE : FALSE;
}
开发者ID:BenjaminWenzel,项目名称:typo3_xlsx_writer,代码行数:14,代码来源:ExcelUtility.php
示例12: json_encode_string
function json_encode_string($in_str)
{
if (mb_check_encoding($in_str) != "UTF-8") {
$in_str = mb_convert_encoding($in_str, "UTF-8");
}
return str_replace('"', '\\"', $in_str);
}
开发者ID:nelsondaza,项目名称:IDMeasure,代码行数:7,代码来源:TemplateTag.php
示例13: coins
function coins($row)
{
// fmt_info (type)
$fmt = "info:ofi/fmt:kev:mtx:";
// 'dissertation' is compatible with the 1.0 spec, but not the 0.1 spec
if (!empty($row['thesis'])) {
$fmt .= "dissertation";
} elseif (preg_match("/Journal/", $row['type'])) {
$fmt .= "journal";
} elseif (preg_match("/Patent/", $row['type'])) {
$fmt .= "patent";
} elseif (preg_match("/Book/", $row['type'])) {
$fmt .= "book";
} else {
$fmt .= "dc";
}
$co = contextObject($row);
$coins = "ctx_ver=Z39.88-2004" . "&rft_val_fmt=" . urlencode($fmt);
foreach ($co as $coKey => $coValue) {
// 'urlencode()' differs from 'rawurlencode() (i.e., RFC1738 encoding)
// in that spaces are encoded as plus (+) signs
$coKey = preg_replace("/au[0-9]*/i", "au", $coKey);
// While COinS does not specify encoding, most javascript tools assume that it is UTF-8
// TODO: use function 'detectCharacterEncoding()' instead of the 'mb_*()' functions?
// if (($contentTypeCharset == "ISO-8859-1") AND (detectCharacterEncoding($coValue) != "UTF-8"))
if (mb_detect_encoding($coValue) != "UTF-8" || !mb_check_encoding($coValue, "UTF-8")) {
$coValue = utf8_encode($coValue);
}
$coins .= "&" . $coKey . "=" . urlencode($coValue);
}
$coins .= "%26ctx_enc%3Dinfo%3Aofi%2Fenc%3AUTF-8";
$coinsSpan = "<span class=\"Z3988\" title=\"" . $coins . "\"></span>";
return $coinsSpan;
}
开发者ID:Olari0,项目名称:Finugriling,代码行数:34,代码来源:openurl.inc.php
示例14: scrapeMarketGroup
function scrapeMarketGroup($url)
{
global $visitedIds;
$html = scraperWiki::scrape($url);
$html = str_replace("\n", "", $html);
preg_match_all("|<a href=\"/importing/61000746/marketgroup/(\\d+?)/\">(.+?)</a>|s", $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$groupId = $match[1];
$groupName = html_entity_decode($match[2]);
//echo $groupName."\n";
if (!in_array($groupId, $visitedIds)) {
$visitedIds[] = $groupId;
scrapeMarketGroup("http://goonmetrics.com/importing/61000746/marketgroup/" . $groupId . "/");
}
}
preg_match_all("|<tr(.*?)>(.*?)<td(.*?)><a href=\"http://games.chruker.dk/eve_online/item.php\\?type_id=(.+?)\" target=\"_blank\">(.*?)<span class=\"dot\" onclick=\"CCPEVE.showMarketDetails\\((.*?)\\)\">(.+?)</span>(.*?)</td>(.*?)<td(.*?)>(.+?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)<td(.*?)>(.+?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)<td(.*?)>(.*?)</td>(.*?)</tr>|s", $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$item = array("itemId" => trim($match[4]), "name" => trim(mb_check_encoding($match[7], 'UTF-8') ? $match[7] : utf8_encode($match[7])), "weekVol" => trim(mb_check_encoding($match[11], 'UTF-8') ? $match[11] : utf8_encode($match[11])), "k6Stock" => trim(mb_check_encoding($match[17], 'UTF-8') ? $match[17] : utf8_encode($match[17])));
$item['weekVol'] = str_replace(",", "", $item['weekVol']);
$item['k6Stock'] = str_replace(",", "", $item['k6Stock']);
$saved = false;
$delay = 0;
while (!$saved && $delay < 600) {
try {
@scraperwiki::save_sqlite(array('itemId'), $item, 'eve_goonmetrics');
$saved = true;
} catch (Exception $e) {
sleep(10);
$delay++;
}
}
}
}
开发者ID:flyeven,项目名称:scraperwiki-scraper-vault,代码行数:33,代码来源:goonmetrics.php
示例15: apply
public function apply($value)
{
if (mb_check_encoding($value, 'UTF-16') && mb_substr_count($value, "") > 0) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-16');
}
return $value;
}
开发者ID:justthefish,项目名称:hesper,代码行数:7,代码来源:Utf16ConverterFilter.php
示例16: checkName
/**
* @param string $name
*
* @return string
*
* @throws RuntimeException
*/
function checkName($name)
{
if ($name == '' || !mb_check_encoding($name, 'UTF-8')) {
throw new \RuntimeException('Invalid currency name: ' . $name);
}
return $name;
}
开发者ID:brick,项目名称:money,代码行数:14,代码来源:import-currencies.php
示例17: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Length) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Length');
}
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$stringValue = (string) $value;
$invalidCharset = false;
if ('UTF8' === ($charset = strtoupper($constraint->charset))) {
$charset = 'UTF-8';
}
if ('UTF-8' === $charset) {
if (!preg_match('//u', $stringValue)) {
$invalidCharset = true;
} elseif (function_exists('utf8_decode')) {
$length = strlen(utf8_decode($stringValue));
} else {
preg_replace('/./u', '', $stringValue, -1, $length);
}
} elseif (function_exists('mb_strlen')) {
if (@mb_check_encoding($stringValue, $constraint->charset)) {
$length = mb_strlen($stringValue, $constraint->charset);
} else {
$invalidCharset = true;
}
} elseif (function_exists('iconv_strlen')) {
$length = @iconv_strlen($stringValue, $constraint->charset);
$invalidCharset = false === $length;
} else {
$length = strlen($stringValue);
}
if ($invalidCharset) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->charsetMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ charset }}', $constraint->charset)->setInvalidValue($value)->addViolation();
} else {
$this->buildViolation($constraint->charsetMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ charset }}', $constraint->charset)->setInvalidValue($value)->addViolation();
}
return;
}
if (null !== $constraint->max && $length > $constraint->max) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->max)->setInvalidValue($value)->setPlural((int) $constraint->max)->setCode(Length::TOO_LONG_ERROR)->addViolation();
} else {
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->max)->setInvalidValue($value)->setPlural((int) $constraint->max)->setCode(Length::TOO_LONG_ERROR)->addViolation();
}
return;
}
if (null !== $constraint->min && $length < $constraint->min) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->min)->setInvalidValue($value)->setPlural((int) $constraint->min)->setCode(Length::TOO_SHORT_ERROR)->addViolation();
} else {
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->min)->setInvalidValue($value)->setPlural((int) $constraint->min)->setCode(Length::TOO_SHORT_ERROR)->addViolation();
}
}
}
开发者ID:Dren-x,项目名称:mobit,代码行数:63,代码来源:LengthValidator.php
示例18: isUtf8
/**
* Test whether a string is valid UTF-8.
*
* The function check for invalid byte sequences, overlong encoding but
* not for different normalisations.
*
* This relies internally on the mbstring function mb_check_encoding()
* hardcoded to check against UTF-8. Whenever the function is not available
* we fallback to a pure PHP implementation. Setting $disableMbstring to
* true will skip the use of mb_check_encoding, this is mostly intended for
* unit testing our internal implementation.
*
* @since 1.21
* @note In MediaWiki 1.21, this function did not provide proper UTF-8 validation.
* In particular, the pure PHP code path did not in fact check for overlong forms.
* Beware of this when backporting code to that version of MediaWiki.
*
* @param string $value String to check
* @param boolean $disableMbstring Whether to use the pure PHP
* implementation instead of trying mb_check_encoding. Intended for unit
* testing. Default: false
*
* @return boolean Whether the given $value is a valid UTF-8 encoded string
*/
static function isUtf8( $value, $disableMbstring = false ) {
$value = (string)$value;
// If the mbstring extension is loaded, use it. However, before PHP 5.4, values above
// U+10FFFF are incorrectly allowed, so we have to check for them separately.
if ( !$disableMbstring && function_exists( 'mb_check_encoding' ) ) {
static $newPHP;
if ( $newPHP === null ) {
$newPHP = !mb_check_encoding( "\xf4\x90\x80\x80", 'UTF-8' );
}
return mb_check_encoding( $value, 'UTF-8' ) &&
( $newPHP || preg_match( "/\xf4[\x90-\xbf]|[\xf5-\xff]/S", $value ) === 0 );
}
if ( preg_match( "/[\x80-\xff]/S", $value ) === 0 ) {
// String contains only ASCII characters, has to be valid
return true;
}
// PCRE implements repetition using recursion; to avoid a stack overflow (and segfault)
// for large input, we check for invalid sequences (<= 5 bytes) rather than valid
// sequences, which can be as long as the input string is. Multiple short regexes are
// used rather than a single long regex for performance.
static $regexes;
if ( $regexes === null ) {
$cont = "[\x80-\xbf]";
$after = "(?!$cont)"; // "(?:[^\x80-\xbf]|$)" would work here
$regexes = array(
// Continuation byte at the start
"/^$cont/",
// ASCII byte followed by a continuation byte
"/[\\x00-\x7f]$cont/S",
// Illegal byte
"/[\xc0\xc1\xf5-\xff]/S",
// Invalid 2-byte sequence, or valid one then an extra continuation byte
"/[\xc2-\xdf](?!$cont$after)/S",
// Invalid 3-byte sequence, or valid one then an extra continuation byte
"/\xe0(?![\xa0-\xbf]$cont$after)/",
"/[\xe1-\xec\xee\xef](?!$cont{2}$after)/S",
"/\xed(?![\x80-\x9f]$cont$after)/",
// Invalid 4-byte sequence, or valid one then an extra continuation byte
"/\xf0(?![\x90-\xbf]$cont{2}$after)/",
"/[\xf1-\xf3](?!$cont{3}$after)/S",
"/\xf4(?![\x80-\x8f]$cont{2}$after)/",
);
}
foreach ( $regexes as $regex ) {
if ( preg_match( $regex, $value ) !== 0 ) {
return false;
}
}
return true;
}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:84,代码来源:StringUtils.php
示例19: correct
public function correct(string $input) : string
{
if (!mb_check_encoding($input, 'UTF-8')) {
throw new SyntaxException(_('SVGファイルの符号化方式 (文字コード) は UTF-8 でなければなりません。'));
}
$parser = xml_parser_create_ns();
$isValid = xml_parse_into_struct($parser, $input, $nodes);
xml_parser_free($parser);
if (!$isValid) {
throw new SyntaxException(_('整形式になっていません。'));
}
$document = new \DOMDocument('1.0', 'UTF-8');
$document->loadXML($input);
// ノードの削除
$root = $document->documentElement;
foreach ((new \DOMXPath($document))->query(self::BLACKLIST) as $node) {
if ($node === $root) {
throw new SyntaxException(_('ルート要素がSVG名前空間に属していません。'));
}
$this->logger->error(sprintf(_('SVG中にノード %s を含めることはできません。'), $node->nodeName));
if ($node->nodeType === XML_ATTRIBUTE_NODE) {
$node->ownerElement->removeAttributeNode($node);
} elseif ($node->parentNode) {
$node->parentNode->removeChild($node);
}
}
return $document->saveXML();
}
开发者ID:esperecyan,项目名称:dictionary-php,代码行数:28,代码来源:SVGValidator.php
示例20: parse
public function parse($markdown)
{
if (!is_string($markdown)) {
throw new InvalidArgumentException('markdown', 'type_invalid');
}
if (!mb_check_encoding($markdown, 'UTF-8')) {
throw new InvalidArgumentException('markdown', 'encoding_invalid');
}
// 目的:我们希望用户输入在 code block 以外的尖括号当成普通字符对待,而不是 HTML 标签被处理
// 替换所有尖括号(成对出现时会被当成标签而忽略)
$markdown = str_replace('<', '<', $markdown);
$markdown = str_replace('>', '>', $markdown);
$html = Marked::render($markdown, ['gfm' => true, 'tables' => true, 'breaks' => true, 'sanitize' => false, 'langPrefix' => 'prettyprint lang-']);
// 恢复 <code> 中的特殊符号(它们被 escape 了两次,第二次是 markdown 引擎)
$pBegin = 0;
while (false !== ($pBegin = stripos($html, '<code>', $pBegin))) {
$pEnd = strpos($html, '</code>', $pBegin + 6);
if ($pEnd === false) {
break;
}
$inner = substr($html, $pBegin + 6, $pEnd - $pBegin - 6);
$inner = str_replace('&lt;', '<', $inner);
$inner = str_replace('&gt;', '>', $inner);
$html = substr_replace($html, $inner, $pBegin + 6, $pEnd - $pBegin - 6);
$pBegin += strlen($inner) + 6;
}
// 由 HTML Purifier 进一步过滤内容确保输入安全
$html = $this->purifier->purify($html);
return $html;
}
开发者ID:Tanklong,项目名称:openvj,代码行数:30,代码来源:MarkdownParser.php
注:本文中的mb_check_encoding函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论