Skip to content
Advertisement

Tag: replace

Add domain to src attribute value if a relative path

I have a text variable which contains multiple images with a relative or absolute path. I need to check if the src attribute starts with http or https then ignore it, but in case it starts with / or something like abc/ then prepend a base url. I tried like below: My output is: Issue here: I got 99% result

Php str_replace one by one in loop

I have a string like A name Tokyo 26, B name Moscov 45, C name Newyork 26, D name Berlin 67, E name Paris 37, F name London 39 I want to replace name words as name1 name2 name3…. so the final string …

Find known string in file then add string prior to it

I need to find a known string inside a config file and then add some content(another string) prior to this. What is the most efficient way to do this? Example: filetomodify.config Desired outcome: I’ve been using fopen to access the file but this only allows to prepend or append content, by default with fwrite. I can’t currently think of an

Advertisement