Dumb_Shock
Dumb_Shock

Reputation: 1008

Removing a space

I have a variable

$abc='akr:/9888/fk4f76mhn';

Another variable

$url =  'http://alpha.com/zidd/id/'.$abc; 

Which is giving me

http://alpha.com/zidd/id/ akr:/9888/fk4f76mhn 

A space is being introduced between id/ and akr:/9888/fk4f76mhn which I do not want.

Is there anything wrong I am doing here?

Upvotes: 1

Views: 94

Answers (4)

Naterade
Naterade

Reputation: 2675

I use: preg_replace( '/\s+/', '', $variable) to remove whitespace from inside a string, and trim, for the start and end. This may help you out. The $variable would be the your $url.

Upvotes: 1

Almo
Almo

Reputation: 15861

Don't you want the following:

$abc='akr:/9888/fk4f76mhn';

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

try

$url =  'http://alpha.com/zidd/id/'.trim($abc); 

Upvotes: 0

Alex Turpin
Alex Turpin

Reputation: 47776

Well you should put quotes around your string literal

$abc = 'akr:/9888/fk4f76mhn';

If you still get a space, you can use trim to remove it:

$url =  'http://alpha.com/zidd/id/' . trim($abc); 

Upvotes: 3

Related Questions