在WordPress帖子/页面的pre
或code
标签中插入代码时遇到麻烦。 WordPress似乎改变了我的单引号和双引号。
参考this page,"
字符("
)与“
和”
字符之间存在差异。另外,在我的代码中使用'
('
)字符时,它被更改为‘
和’
。
因此,在帖子中,我可能会包含以下代码段:
<pre><code>
$server_name = app_config('server_name');
</code></pre>
WordPress将其显示为:
$server_name = app_config(‘server_name’);
注意如何更改单引号。
要在代码中将单引号保持为'
字符,将双引号保持为"
字符,我需要做什么?
答案 0 :(得分:1)
如果其他人遇到此问题,只需提供答案。该代码是通过使用简码显示的,而WordPress简码是经过“纹理化”(过滤)的,这将更改引号。
您必须排除用于通过NSString *formattedDuration = @"";
NSString *durationregX = @"^(P\\d+DT)[A-Z0-9]+$";
NSPredicate *checking = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", durationregX];
BOOL isDayLengthVideo = [checking evaluateWithObject: duration];
long getDayHours = 0;
if(isDayLengthVideo){
NSArray *sliceDuration = [duration componentsSeparatedByString:@"DT"];
NSString *getDay = [sliceDuration[0] stringByReplacingOccurrencesOfString:@"P" withString:@""];
getDayHours = (long)[getDay integerValue] * 24;
formattedDuration = [[[sliceDuration[1] stringByReplacingOccurrencesOfString:@"H" withString:@":"] stringByReplacingOccurrencesOfString:@"M" withString:@":"] stringByReplacingOccurrencesOfString:@"S" withString:@""];
}else{
formattedDuration = [[[[duration stringByReplacingOccurrencesOfString:@"PT" withString:@""] stringByReplacingOccurrencesOfString:@"H" withString:@":"] stringByReplacingOccurrencesOfString:@"M" withString:@":"] stringByReplacingOccurrencesOfString:@"S" withString:@""];
}
NSString *clean_duration = @"";
NSArray *components = [formattedDuration componentsSeparatedByString:@":"];
NSInteger loopchecker = 0;
for (NSString *component in components) {
loopchecker++;
clean_duration = clean_duration.length > 0 ? [NSString stringWithFormat:@"%@:", clean_duration] : clean_duration; // ""
if(component.length < 2){
clean_duration = loopchecker == 1 && isDayLengthVideo ? [NSString stringWithFormat:@"%ld", ([component integerValue] + getDayHours)] : [NSString stringWithFormat:@"%@0%@", clean_duration, component];
return clean_duration;
continue;
}
clean_duration = [NSString stringWithFormat: @"%@%@", clean_duration, component];
}
return clean_duration;
过滤器显示代码的短代码,例如documented here。
no_texturize_shortcodes
答案 1 :(得分:-1)
这是针对XSS攻击的防御机制。尝试像建议JROB一样编写它。
最诚挚的问候,