SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Remove charater between / and +
-
May 27, 2009, 20:48 #1
- Join Date
- Dec 2003
- Location
- NH
- Posts
- 61
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Remove charater between / and +
Hi,
I am trying to remove the words between / and +
Example:
=ft myers / sw florida+
Desired output would be
=ft myers+
Another example
=flagstaff / area+
Desired output would be
=flagstaff+
I think I need a trim function but cant get it to work.
Thanks for any feedback.
Nate
-
May 27, 2009, 21:02 #2
- Join Date
- Nov 2005
- Posts
- 1,191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could use php string manipulation functions http://nz.php.net/strings have a look at strpos() and substr()
Or you could use regular expressions http://nz2.php.net/manual/en/ref.pcre.php
-
May 27, 2009, 21:15 #3Code PHP:
$myString='=ft myers / sw florida+'; $myString = preg_replace("/\h*\/.+/","+",$myString); echo $myString;
Tweep List adds an avatar menu to Twitter (open source)
Word Stats shows your most used words on Twitter
-
May 27, 2009, 23:44 #4
- Join Date
- Dec 2003
- Location
- NH
- Posts
- 61
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you both for your replies...ended up using the code Glen supplied and it work great.
Thanks again,
Nate
-
May 27, 2009, 23:58 #5
- Join Date
- May 2009
- Posts
- 9
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
its always advisable to use templates but its better to create own method rather than posting on web forms for help. Using simple arrays will solve this prob very easily but coders want short cuts even in easier things this only reduces coding capability nothing more. Thats not advisable.
-
May 28, 2009, 02:36 #6
Bear in mind that glenngould's code would truncate strings containing a forward slash without a suffixed plus symbol.
For example:
PHP Code:$myString='=ft myers / sw florida';
$myString = preg_replace("/\h*\/.+/","+",$myString);
echo $myString; // =ft myers+
Bookmarks