Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Remove Duplicate Characters in Strings With Laravel

    Remove Duplicate Characters in Strings With Laravel

    August 13, 2024

    If you need to remove string duplication in Laravel and PHP applications, Laravel v11.20 adds a new method named deduplicate to the String helpers, which allows you to quickly and easily remove duplicate characters.

    use IlluminateSupport{Str,Stringable};

    $string = ‘/usr/local////path/to///desktop’;

    Str::deduplicate($string, ‘/’);
    // “/usr/local/path/to/desktop”

    (new Stringable($string))->deduplicate(‘/’)->toString();
    // “/usr/local/path/to/desktop”

    The default replacement character in the deduplicate() method is a space character, which could also be a use for the squish() helper introduced in Laravel v9.7.0. Let me illustrate when squish() might be a better choice to remove extra spaces:

    Str::deduplicate(‘ John Smith Jr. ‘); // ” John Smith Jr. “
    Str::squish(‘ John Smith Jr. ‘); // “John Smith Jr.”

    Note the extra space ‘ ‘ characters at the beginning and end using deduplicate(), which is by design. Deduplicate is used to replace consecutive instances of a given character with a single character in the given string. Squish also removes other space characters, such as newlines and tabs:

    // Each example returns `laravel php framework`:
    Str::squish(‘ laravel php framework ‘));
    Str::squish(“laravelttphpnnframework”);
    Str::squish(‘
    laravel
    php
    framework
    ‘);

    The post Remove Duplicate Characters in Strings With Laravel appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleNIST approves three cryptographic algorithms capable of withstanding quantum computers
    Next Article Meet Ramya Jayakrishnan, a Technical Architect Fostering a Culture of Learning at Perficient

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-47893 – VMware GPU Firmware Memory Disclosure

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Here’s how to get a free iPhone 16 Pro from T-Mobile with no trade-in required

    News & Updates

    Understanding Memorization in Diffusion Models: A Statistical Physics Approach to Manifold-Supported Data

    Development

    Amazon India Customer Raises Data Breach Concerns After Receiving Duplicate Orders, Fake Products

    Development

    Centralize model governance with SageMaker Model Registry Resource Access Manager sharing

    Development

    Highlights

    Databases

    How the Amazon TimeHub team designed resiliency and high availability for their data replication framework: Part 2

    December 18, 2024

    In How the Amazon Timehub team built a data replication framework using AWS DMS: Part…

    LinuxConsole – lightweight distribution

    February 17, 2025

    Usability and Experience (UX) in Universal Design Series: Cognitive Disabilities – 3

    June 27, 2024

    Choosing the Right Pricing Strategy for Your Digital Projects

    August 18, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.