Skip to content
Advertisement

Tag: string

remove part of string after delimiter in php

I have seen other I have a string ” cccc cccc – fff” I need to return “cccc cccc” I don’t need to delimiter too I tried to echo the result of substr($mystring , 0, strpos($mystring , “-“)); but it return nothing I also tried resulted returned the main string and trash resulted nothing Update: i’m using wordpress and for

Php base base64 encode and decode not working correctly

I want to encode and decode in php using base64, but the encode and decode function does not give me correct output. I am using code from online php functions. I encode this string “best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي” and get the output: “YmVzdCBhcmFiaWMgc29uZ3MgbG92ZXMgMjAxMyBub25zdG9wINij2YHYttmEINmF2YYg2KfZhNij2LrYp9mG2Yog2KfZhNit2Kgg2KfZhNis2K/ZitivINmD2YTZhdin2Kog2KfZhNi52LHYqNmK” When I use this php code it does

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

Visually same string gives different var_dumps in php

UPDATE: Anwer is here PHP unserialize fails with non-encoded characters? I’m trying to match objects with in_array. This works fine except for the object with this string as a property. Visually they are the same, but when I do a var_dump PHP sees different lengths. var_dump results: What can be the cause? Some ascii value I don’t know of? Answer

Replace multiple dashes with one dash

I have a string which looks like this: I want to replace the multiple dashes with a single one. So the expected output would be: I tried to use str_replace(), but I have to write the code again for every possible amount of dashes. So how can I replace any amount of dashes with a single one? For Rizier: Tried:

Advertisement