Questions tagged [str-replace]

Substituting involves the process of inspecting a string for a particular substring and substituting it with an alternative string.

Eliminating the final whitespace within a string

Is there a way to remove the trailing space from a string without using regular expressions in PHP? I want to transform my string from this: (s)a(s)b(s) To this desired format: (s)a(s)b I'm looking for an alternative solution that searches for ' ' ...

Replacing parts of a string with str_replace function

I'm currently exploring the functionalities of str_replace and using curly brackets. When I input {the_title} in this line, I understand that it will be replaced with the value from the $some_runtime_generated_title array. But what exactly does the first p ...

"Encountered error converting array to string while attempting to swap out two elements

Here is the code snippet I am working with: <?php $url_constructor = "http://myecommerce.dev/edit/article_name/article_id"; $cart_line_link = str_replace($url_constructor, array( 'article_id', 'article_name' ) , array( $ ...

Extract only one term in PHP

I've searched high and low but haven't found a solution that fits my needs. All I want to keep is the word you. $words = "you,us,them,our"; $keep = "you,"; The code provided seems to do the opposite of what I need: $words = str_replace("$keep", "", $w ...

PHP - Substituting Characters in a Text

I'm really struggling to understand the str_replace function. Let me explain: Consider this string: $string = 'ababcd'; My goal is to replace all 'a' with 'b', 'b' with 'c', and 'c' with ...

Utilize custom {tags} for replacing strings in a CSS file using str_replace in PHP

My code consists of a script that updates a CSS file based on user input from an html form. The script executes a str_replace function, scanning the CSS file for specific "tags". For example: html,body { background: {bgcolor} url(../images/bg.jpg) re ...

Eliminate certain characters from the rows within a designated column

Starting out with a simple question. I've attempted to remove hyphens and the first two characters of the personal numbers in the personal number column. Despite my efforts, the hyphens remain in my dataset and I encounter an error when trying to repl ...

Keep only the PHP characters intact while replacing all others in the given string

I need help with extracting the year 1988 from a string that says "Trade Card Catalogue 1988 Edition". Is there a more efficient solution instead of using an array, str_replace, and trim? $string = 'Trade Card Catalogue 1988 Edition'; $letters = array('a' ...

Transforming a pre-existing date format into a new structure using regular expressions

When I have $date = $run['at'];, the output is 2013-06-03T16:52:24Z. How can I modify it to extract "d M Y, H:i" format for example? ...