Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove spaces in field

Participant ,
Jul 26, 2009 Jul 26, 2009

I have a database of names of people in this format

First Second

I want to take these names from the URL then REMOVE THE WHITE SPACES in the middle of the URL then add .gif to the end to turn it into the reference for an image.

So I want to get this out:    FirstSecond.gif

I have read through all the other posts on similar questions, but nothing seems to work!

I am using this code (not that I understand it) to do the stripping.....

<?php

$sTestString = '<?php echo ($_GET['secondary']); ?>';

$sPattern = '/\s*/m';

$sReplace = '';

echo preg_replace( $sPattern, $sReplace, $sTestString ); ?>

I get this error:

Parse error: syntax error, unexpected T_STRING in /content/HostingPlus/h/a/hands-together.org/web/testspaces.php on line 3

Any ideas? or is there something REALLY simple I can do in formats to get this to work. It seems so basic !

Thanks

TOPICS
Server side applications
726
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2009 Jul 26, 2009

I am using this code (not that I understand it) to do the stripping.....

Using code without understanding it is a rapid way to hair loss.

The reason you're getting a parse error is because you're nesting PHP tags inside PHP tags. You can't do it.

This:

$sTestString = '<?php echo ($_GET['secondary']); ?>';

Should be this:

$sTestString = $_GET['secondary'];

In your question, you refer to a database and a URL. Where is the data coming from: the database or a URL?

If it's coming from the database, you can do it all with SQL:

SELECT *, CONCAT(First, Second, '.gif') AS image

FROM myTable

Assuming that First and Second are the names of columns in your database, this will produce a result similar to DavidPowers.gif in the recordset, which can be retrieved as "image".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2009 Jul 26, 2009

That will probably explain my bald patch then!

Sorry, no I am using just the URL to be the starting point for the

link to an image. The URL has a space in the middle which is being

replaced by %20, so all I need to do is to take the URL, take out the

space, then add the rest of the link.

C

Colin Walton

WaltonCreative

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2009 Jul 26, 2009
LATEST

That will probably explain my bald patch then!

Well, I've still got a full head of hair - and I'm way past the first (and second) flush of youth.

If you're getting it from a URL parameter, just ust str_replace().

$image = str_replace(' ', '', $_GET['variable_name']) . 'gif';

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines