You might be overthinking it. While the substr()
method will work perfectly it might be simpler to use rtrim()
to remove any trailing slashes and then add one on.
$path = rtrim($path, "https://stackoverflow.com/") . "https://stackoverflow.com/";
Caution: this will trim multiple trailing forward slashes. so .//////
becomes ./
Related Contents:
- How to remove non-alphanumeric characters?
- How can I use Guzzle to send a POST request in JSON?
- Getting the location from an IP address [closed]
- PHP substring extraction. Get the string before the first ‘/’ or the whole string
- Laravel csrf token mismatch for ajax POST Request
- Get current domain
- Why is === faster than == in PHP?
- How to extract img src, title and alt from html using php? [duplicate]
- PHP script to loop through all of the files in a directory?
- What is the canonical way to determine commandline vs. http execution of a PHP script?
- Run PHP Task Asynchronously
- How to create an array for JSON using PHP?
- Alternative for PHP_excel
- Reset PHP Array Index
- Using CSS in Laravel views?
- How to [recursively] Zip a directory in PHP? [duplicate]
- How do I resolve a HTTP 414 “Request URI too long” error?
- Formatting Phone Numbers in PHP
- Can I do Model->where(‘id’, ARRAY) multiple where conditions?
- mysqli_real_connect(): (HY000/2002): No such file or directory
- Why I’m getting ‘Non-static method should not be called statically’ when invoking a method in a Eloquent model?
- Create an assoc array with equal keys and values from a regular array
- Maximum size of a PHP session
- php: try-catch not catching all exceptions
- failed to open stream: HTTP wrapper does not support writeable connections
- file_get_contents() Breaks Up UTF-8 Characters
- Check if a string is an email address in PHP
- How to compare 2 strings alphabetically in PHP?
- Forbidden :You don’t have permission to access /phpmyadmin on this server
- PHP StdErr after Exec()
- Cannot connect to MySQL 4.1+ using old authentication
- How to retrieve all Variables from a Twig Template?
- Convert plain text URLs into HTML hyperlinks in PHP
- PHP file listing multiple file extensions
- array_map inline anonymous function [duplicate]
- Laravel migrations change default value of column
- How to clear browser cache with php?
- Laravel migrations nice way of disabling foreign key checks
- phpMyAdmin Duplicate Table
- Generic “Killed” error in PHP script
- Execute root commands via PHP
- New language on top of PHP?
- difference between two arrays
- str_replace with array
- Remove zero values from a PHP array
- Looping Through All a Server’s Sessions in PHP
- Undefined index with $_POST [duplicate]
- How to bulk update mysql data with one query?
- Replace deprecated preg_replace /e with preg_replace_callback [duplicate]
- Create class instance from within static method