本文整理汇总了PHP中nnText::getAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP nnText::getAttributes方法的具体用法?PHP nnText::getAttributes怎么用?PHP nnText::getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nnText
的用法示例。
在下文中一共展示了nnText::getAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: combineAttributes
/**
* combine attribute values in a tag string
*/
public static function combineAttributes($string1, $string2)
{
$attribs1 = is_array($string1) ? $string1 : nnText::getAttributes($string1);
$attribs2 = is_array($string2) ? $string2 : nnText::getAttributes($string2);
$dublicate_attribs = array_intersect_key($attribs1, $attribs2);
// Fill $attribs with the unique ids
$attribs = array_diff_key($attribs1, $attribs2) + array_diff_key($attribs2, $attribs1);
// Add/combine the duplicate ids
$single_value_attributes = array('id', 'href');
foreach ($dublicate_attribs as $key => $val) {
if (in_array($key, $single_value_attributes)) {
$attribs[$key] = $attribs2[$key];
continue;
}
// Combine strings, but remove duplicates
// "aaa bbb" + "aaa ccc" = "aaa bbb ccc"
// use a ';' as a concatenated for javascript values (keys beginning with 'on')
$glue = substr($key, 0, 2) == 'on' ? ';' : ' ';
$attribs[$key] = implode($glue, array_merge(explode($glue, $attribs1[$key]), explode($glue, $attribs2[$key])));
}
foreach ($attribs as $key => &$val) {
$val = $key . '="' . $val . '"';
}
return implode(' ', $attribs);
}
示例2: combineAttributes
/**
* combine attribute values in a tag string
*/
public static function combineAttributes($string1, $string2)
{
$attribs1 = is_array($string1) ? $string1 : nnText::getAttributes($string1);
$attribs2 = is_array($string2) ? $string2 : nnText::getAttributes($string2);
$dublicate_attribs = array_intersect_key($attribs1, $attribs2);
// Fill $attribs with the unique ids
$attribs = array_diff_key($attribs1, $attribs2) + array_diff_key($attribs2, $attribs1);
// Add/combine the duplicate ids
$single_value_attributes = array('id');
foreach ($dublicate_attribs as $key => $val) {
if (in_array($key, $single_value_attributes)) {
$attribs[$key] = $attribs2[$key];
continue;
}
// Combine strings, but remove duplicates
// "aaa bbb" + "aaa ccc" = "aaa bbb ccc"
$attribs[$key] = implode(' ', explode(' ', $attribs1[$key]) + explode(' ', $attribs2[$key]));
}
foreach ($attribs as $key => &$val) {
$val = $key . '="' . $val . '"';
}
return implode(' ', $attribs);
}