Jump to content

[SOLVED] Help removing white space from php variables inside links.


dmIllithid

Recommended Posts

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?

Link to comment
Share on other sites

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']);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.