dmIllithid Posted May 25, 2007 Share Posted May 25, 2007 Let me start by saying that RegEx is way beyond me. I have searched on this website and other websites for possible solutions to my issue and have crashed in a ball of flames every time I thought I found something. It may be that the solution I am looking for is not possible. Anyways, here is my issue. I am passing variables from 1 page to another. The following snippet is the link in reference. <?php $poem_block = "$poem_item[author] - <a href=\"javascript:popUp('content.php?page=poem&&author=$author&&title=$title')\" title=\"Click to view\">$poem_item[title]</a><hr />"; ?> This works fine, the variables are passed as expected and without problem. My problem is that I have OCD(obsessive compulsive disorder), and when I am writting script I have to do things so that they are in compliance with w3c. Now, the issue with the link is this : each variable has data pulled from my db such as <?php $title = $poem_item[title]; ?> The data for $poem_item[title] = So Much Depends Upon. The data for $poem_item[author] = Amanda Noble. So when the user runs their mouse over the link they see javascript:popUp('content.php?page=poem&&author=Amanda Noble&&title=So Much Depends Upon') I need to remove the whitespace in the link as this is my biggest issue. Again, due to my OCD and trying to comply with w3c. my question : Is it possible to remove the whitespace? If so, can anybody help me? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 1. There should only be one ampersand (&) between those arguments. 2. No need for regular expressions. Use urlencode(). Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 25, 2007 Share Posted May 25, 2007 My problem is that I have OCD(obsessive compulsive disorder), and when I am writting script I have to do things so that they are in compliance with w3c. Nah. That's just good coding What Wildbug is suggesting in #2 above will convert your spaces to their encoded equivalent %20, so it will appear to be without whitespace. If you are truly trying to remove all whitespace from the strings, you could do something as simple as this: <?php function stripWhite($string) { return preg_replace('|\s+|', '', $string); } $author = stripWhite($poem_item['author']); $title = stripWhite($poem_item['title']); ?> Quote Link to comment Share on other sites More sharing options...
dmIllithid Posted May 25, 2007 Author Share Posted May 25, 2007 Problem solved. After reviewing both suggestions, I decided that the urlencode() method was really what I needed. Thank you to you both. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.