RE: [PHP] Novice question - please help
| From: | Rick Emery | Date: | Mon, 11 Feb 2002 21:42:16 +0000 |
| Subject: | RE: [PHP] Novice question - please help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-84313@lists.php.net to get a copy of this message | ||
ereg_replace() is your friend here.
<?php
$oldstring = "x + y ";
$newstring = ereg_replace(" ","",$oldstring);
print "#$newstring#";
?>
will print #x+y#
-----Original Message-----
From: brendan conroy [mailto:brendanconroy80@hotmail.com]
Sent: Monday, February 11, 2002 3:16 PM
To: php-general@lists.php.net
Subject: [PHP] Novice question - please help
Hi,
THANK YOU for reading this.I would really appreciate it if someone could
please email me if they know any easy way or an existing function for
removing an unknown ammount of space characters from an array.
Iam having an awful lot of trouble trying to remove multiple space
characters from an array,
ie. x + y
123456789
where there are three or more spaces in a row(rep'd above by 234 & 678),
basically weird user input.
I have written code already, but I cant see where Ive gone wrong, here it is
if you care to look at it, and have a good chuckle, told you I was a novice!
I included the start page that allows you to see what the code does, in you
want to look at it.
Thank you for your time, I'd really appreciate any replies!
<HTML>
<BODY>
<?
$x = 0;
$ay=array();
$g=array();
$c = explode (' ', $a);
for($q=0;$q<=count($c);$q++)
{
echo"<font color=green>";
echo"$c[$q]";
echo"<HR>";
echo"</font>";
}
$c=array_reverse($c);
for($w = 0;$w<count($c);$w++)
{
echo $w;
$e=array_pop($c);
if(($e == ' ')||($e == NULL))
{
echo"hi space";
array_push($ay,$e);
echo"<HR>";
}
else
{
echo"hi no space";
array_push($g,$e);
}
}
echo(count($g));
for($x=0;$x<=(count($g));$x++)
{
echo"<BR>";
echo"$g[$x]";
echo"<HR>";
}
?>
</BODY>
</HTML>
==============================
start page code
======================
<html>
<head>
<title>npage.php</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form action="newplan2.php" method=post>
enter polynomial <? echo "$i";?> here:<input type="text"
name="a">
<input type="submit" name="submit" value="Submit Pols!">
</body>
</html>
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php