logo
down
shadow

Replace all spaces and special symbols with dash in URL using PHP language


Replace all spaces and special symbols with dash in URL using PHP language

Content Index :

Replace all spaces and special symbols with dash in URL using PHP language
Tag : php , By : Michael T.
Date : January 10 2021, 01:47 PM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

in url's, what's better to use to replace spaces, + or a dash? url encode does + , google recommend a dash


Tag : php , By : rhinojosa
Date : March 29 2020, 07:55 AM
hope this fix your issue urlencode() is intended for query parameters only (everything that goes after the ?). + is a special character inside the query part of the URL, and represents a literal space; literal + character needs to be percent-encoded. rawurlencode() is intended for all other URL parts, and it does not encode space as +.
Dashes on the other hand are not special characters and represent themselves in the URL directly.

Remove special symbols and extra spaces and replace with underscore using the replace method


Tag : javascript , By : Mariocki
Date : March 29 2020, 07:55 AM
hop of those help? Your regular expression [^a-zA-Z0-9]\s/g says match any character that is not a number or letter followed by a space.
Remove the \s and you should get what you are after if you want a _ for every special character.
var newString = str.replace(/[^A-Z0-9]/ig, "_");
var newString = str.replace(/[^A-Z0-9]+/ig, "_");

Properly sort an NSString array including words starting with a dash or special symbols (for a dictionary)


Tag : iphone , By : UnKnownUser
Date : March 29 2020, 07:55 AM
may help you . to @manecosta's answer. The complete solution is rather complicated, though:
#define hasDash hasPrefix:@"-"
// ...

NSMutableArray *arr = [NSMutableArray arrayWithArray:@[@"-con", @"baby",
    @"context", @"zebra", @"-ar", @"-am", @"Big", @"chastity",
    @"-b", @"American", @"brute"]];

[arr sortUsingComparator:^NSComparisonResult(NSString *s1, NSString *s2) {
    if (![s1 hasDash] && ![s2 hasDash]) {
        return [s1 caseInsensitiveCompare:s2];
    } else if ([s1 hasDash] && [s2 hasDash]) {
        NSString *c1 = [s1 substringFromIndex:1];
        NSString *c2 = [s2 substringFromIndex:1];
        return [c1 caseInsensitiveCompare:c2];
    } else if ([s1 hasDash]) {
        NSString *c1 = [s1 substringFromIndex:1];
        if ([[[c1 substringToIndex:1] uppercaseString]
             isEqualToString:[[s2 substringToIndex:1] uppercaseString]]) {
            return NSOrderedAscending;
        } else {
            return [c1 caseInsensitiveCompare:s2];
        }
    } else { // if ([s2 hasDash]) {
        NSString *c2 = [s2 substringFromIndex:1];
        if ([[[s1 substringToIndex:1] uppercaseString]
             isEqualToString:[[c2 substringToIndex:1] uppercaseString]]) {
            return NSOrderedDescending;
        } else {
            return [s1 caseInsensitiveCompare:c2];
        }
    }
}];

java regex replace special characters and spaces with dash


Tag : java , By : Chandra P Singh
Date : March 29 2020, 07:55 AM
may help you . You're close, you just need to add a quantifier to the expression to allow it to match more than one character.
/[^A-Za-z0-9]+/
"Town & Country".replaceAll("[^A-Za-z0-9]+", "-").toLowerCase();

String replace to replace spaces and maintain dash


Tag : php , By : Stephen
Date : March 29 2020, 07:55 AM
hop of those help? I am trying to convert: , You might remove - from your RegEx pattern:
function phpslug($string)
{
    $slug = preg_replace('/[^a-z0-9]+/', '_', strtolower(trim($string)));
    return $slug;
}

var_dump(phpslug("  Long Grain IRRI-6 White Rice  "));
function phpslug($string)
{
    $slug = preg_replace('/[-\s]+/', '_', strtolower(trim($string)));
    return $slug;
}

var_dump(phpslug("  Long Grain IRRI-6 White Rice  "));
 string(28) "long_grain_irri_6_white_rice"
Related Posts Related QUESTIONS :
  • PHP4 to PHP5 Migration
  • Making a production build of a PHP project with Subversion
  • Add 1 to a field
  • Better Random Generating PHP
  • Accessing a CONST attribute of series of Classes
  • Locking a SQL Server Database with PHP
  • Version control PHP Web Project
  • How to sell Python to a client/boss/person
  • How to easily consume a web service from PHP
  • How to include PHP files that require an absolute path?
  • Multi-Paradigm Languages
  • PHP Error - Uploading a file
  • MySQL/Apache Error in PHP MySQL query
  • Lightweight IDE for Linux
  • How to search a row that has been joined with another table
  • How to do mysql LEFT JOIN for Google multiple line chart (php, mysql)?
  • Find the two longest strings separated by dash in PHP
  • Cannot access private property with Set method in Symfony
  • How to compare 2 array of PHP objects then fill in empty string if data not match?
  • strtotime gives back false result to strings in an array
  • How to create Url that contain name and id laravel
  • Codeigniter: Models not working with an error: Undefined property: CI_Loader
  • How to use + or - operators as parameters in Doctrine prepared SQL statement?
  • How to run scrapy with url parameters from php on linux debian
  • Preg matching imgur.com links
  • Php - Code comparing value of database to the value send by android app
  • Laravel pagination object in javascript
  • Error in validating message of no votes PHP
  • Symfony site on Azure with ClearDB connection
  • Woocommerce upsell with checkboxes
  • How to login/logout with Hybridauth 3?
  • Convert INT number in PHP
  • php/mysql. selecting 2 common fields in 2 tables
  • Expand an string based on values in an array in PHP
  • When you absolutely have to manually escape SQL in CakePHP 3.4.7
  • Htaccess redirecting wrong page
  • Laravel Optional WHERE clause
  • PHP unpack overlfow variable memory limit
  • How to check the URL's structure using PHP preg_match?
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com