本文整理匯總了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);
}