Welcome Guest, Not a member yet? Register   Sign In
string manipulation help
#1

[eluser]basty_dread[/eluser]
Hello guys i need help on the preg_replace()

I want to remove the spaces on this string:
Code:
$keyword = "Law Firm Action";
and replace it with "/" so the output will be

Law/Firm/Action

I tried this code but i had an error:
Code:
$keyword = "Law Firm Action";
$search = ' ';
$replace='/';
$replacedkeyword = preg_replace($search, $replace, $key_word);

Please Help me thank you.
#2

[eluser]John_Betong[/eluser]
[quote author="basty_dread" date="1260455112"]Hello guys i need help on the preg_replace()

I want to remove the spaces on this string:
Code:
$keyword = "Law Firm Action";
and replace it with "/" so the output will be

Law/Firm/Action

I tried this code but i had an error:
Code:
$keyword = "Law Firm Action";
$search = ' ';
$replace='/';
$replacedkeyword = preg_replace($search, $replace, $key_word);
 
Why not use str_replace(...)
Code:
$keyword = "Law Firm Action";
        $s = str_replace(' ', '/', $keyword);
Please Help me thank you.[/quote]
 
 
 
#3

[eluser]Sire[/eluser]
If you need to use preg_replace, you need the delimiters on your $search, I'll use a / in this example
Code:
$search = '/ /';
#4

[eluser]basty_dread[/eluser]
thank's a lot for the reply. i didnt know i need to put delimitter on my $searcg,,
thank you for the help
#5

[eluser]theprodigy[/eluser]
Quote:$keyword = "Law Firm Action";
$search = ' ';
$replace='/';
$replacedkeyword = preg_replace($search, $replace, $key_word);

It also seems you set $keyword, but are running your preg_replace on $key_word.




Theme © iAndrew 2016 - Forum software by © MyBB