How to ignore minus sign in arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Namjies
Forum Newbie
Posts: 3
Joined: Mon Feb 23, 2009 11:56 am

How to ignore minus sign in arrays

Post by Namjies »

I don't know if it can be done but I'd like an to create from an array a list of urls and the urls contain -, which gets interpreted as minus so the urls get calculated as letters minus letters which ends up showing all url as 0.html

Is there a way to ignore the minus sign in an array?

Thank you.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to ignore minus sign in arrays

Post by John Cartwright »

str_replace()
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to ignore minus sign in arrays

Post by requinix »

Namjies wrote:I don't know if it can be done but I'd like an to create from an array a list of urls and the urls contain -, which gets interpreted as minus so the urls get calculated as letters minus letters which ends up showing all url as 0.html
...How are you turning a string with a URL into a mathematical expression? Why?
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: How to ignore minus sign in arrays

Post by semlar »

Yeah, strings don't work this way. It sounds like there's something wrong with the way you're storing the value.

Or, considering all of the URLs are returning the same value, maybe your output is being contaminated somehow.
Namjies
Forum Newbie
Posts: 3
Joined: Mon Feb 23, 2009 11:56 am

Re: How to ignore minus sign in arrays

Post by Namjies »

That should make it more clear with an example:

Code: Select all

 $games = array(submachine-0, submachine-1, submachine-2, submachine-3);
foreach ($games as $game){echo '
<div class="square"><a href="'.$game.'.html"><img src="http://example.com/games/'.$game.'.png" alt="'.$game.'" border="0" /><br/>'.$game.'</a></div>
';}
creates links to 0.html, -1.html, -2,html etc. values. I guessed the array interpreted the expression as letters without value and minus a number. So it actually works as long as there is no hyphen in the urls I want to create.

Simply for rendering games lists easily and changing the game folder regularly and easily to prevent leech of flash files. Might seem stupid but I'm creating a game website based on a few php lines instead of a premade script with a database. I find it useful to learn PHP. Already learned includes, a few server variables, variables, if and echo. I'm moving to arrays. But I couldn't find my answer on Google with this one.

Anyone can help with this? Thanks.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: How to ignore minus sign in arrays

Post by Eran »

strings as array values/keys are the same as strings elsewhere - you need to wrap them with quotes.

Code: Select all

$games = array('submachine-0', 'submachine-1', 'submachine-2', 'submachine-3');
Namjies
Forum Newbie
Posts: 3
Joined: Mon Feb 23, 2009 11:56 am

Re: How to ignore minus sign in arrays

Post by Namjies »

ah, thank you so much! Easily fixed. Now I guess I have arrays creation added to my PHP knowledge.
Post Reply