function _print_replace_spaces in Printer, email and PDF versions 6
Same name and namespace in other branches
- 7.2 includes/print.inc \_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 - Process the send by-email form submission.
- _print_pdf_dompdf in print_pdf/
print_pdf.pages.inc - Generate the PDF file using the dompdf library
File
- ./
print.module, line 930 - Displays Printer-friendly versions of Drupal pages.
Code
function _print_replace_spaces($matches) {
// first, 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 may 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;
}