function _print_replace_spaces in Printer, email and PDF versions 7.2
Same name and namespace in other branches
- 6 print.module \_print_replace_spaces()
- 7 print.module \_print_replace_spaces()
Callback function for the preg_replace_callback replacing spaces with %20.
Replace spaces in URLs with %20
Parameters
array $matches: Array with the matched tag patterns, usually <a...>+text+</a>.
Return value
string tag with re-written URL
2 string references to '_print_replace_spaces'
- print_mail_form_submit in print_mail/
print_mail.inc - Form submission handler for print_mail_form().
- print_pdf_dompdf_print_pdf_generate in print_pdf/
lib_handlers/ print_pdf_dompdf/ print_pdf_dompdf.pages.inc - Implements hook_print_pdf_generate().
File
- includes/
print.inc, line 42 - Common functions used by several of the print modules.
Code
function _print_replace_spaces($matches) {
// Split the html into the different tag attributes.
$pattern = '!\\s*(\\w+\\s*=\\s*"(?:\\\\"|[^"])*")\\s*|\\s*(\\w+\\s*=\\s*\'(?:\\\\\'|[^\'])*\')\\s*|\\s*(\\w+\\s*=\\s*\\w+)\\s*|\\s+!';
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($attribs as $key => $value) {
$attribs[$key] = preg_replace('!(\\w)\\s*=\\s*(.*)!', '$1=$2', $value);
}
$size = count($attribs);
for ($i = 1; $i < $size; $i++) {
// If the attribute is href or src, we need to rewrite the URL in the value.
if (preg_match('!^(?:href|src)\\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\v\"'");
$new_url = str_replace(' ', '%20', $url);
$matches[1] = str_replace($url, $new_url, $matches[1]);
}
}
$ret = '<' . $matches[1] . '>';
if (count($matches) == 4) {
$ret .= $matches[2] . $matches[3];
}
return $ret;
}