Jump to content

preg_replace() and trim()


gordon.c

Recommended Posts

hi,

 

these two functions preg_replace() and trim() work fine on my virtual apache server however they dont work online on the webhosting server.

 

What could be the issue. Is it the version of PHP? My virtual server runs php 4.4.9 the webhosting runs probably the latest possible 5.something.

Or is there some setting in .htaccess I shall do, to make it work?

 

Thank you for help

Link to comment
https://forums.phpfreaks.com/topic/206551-preg_replace-and-trim/
Share on other sites

hi,

 

these two functions preg_replace() and trim() work fine on my virtual apache server however they dont work online on the webhosting server.

 

What could be the issue. Is it the version of PHP? My virtual server runs php 4.4.9 the webhosting runs probably the latest possible 5.something.

Or is there some setting in .htaccess I shall do, to make it work?

 

Thank you for help

 

What do you mean they don't work?  Care to post some code and the results?

Very familiar method that simply strips a string off dangerous characters. (For creating nice looking URLs)

 

<?php
function RemoveMultibyte($text) {
    $new = $text;
    $new = preg_replace('~[^\\pL0-9_]+~u', '-', $new);
    $new = trim($new, "-");
    $new = strtolower($new);
    $new = preg_replace('~[^-a-z0-9_]+~', '', $new);

return $new;
}
?>

 

Input: píča kunda

Output: pa-kunda

 

 

On my virtual machine, it would do its work correctly, replace blanks for dashes, remove any non-english chars....

 

On hosting server this same function will not return any output at all.

What does this produce:

function RemoveMultibyte($text) {
    $new = $text;
echo $new . '<br>';
    $new = preg_replace('~[^\\pL0-9_]+~u', '-', $new);
echo $new . '<br>';
    $new = trim($new, "-");
echo $new . '<br>';
    $new = strtolower($new);
echo $new . '<br>';
    $new = preg_replace('~[^-a-z0-9_]+~', '', $new);
echo $new . '<br>';

    return $new;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.