SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Jul 11, 2007, 11:03 #1
A script to remove anything between ()?
I have a list and some of the listing have parentheses with words in between them. I want to remove the parentheses and the words in between. Anyone know a simple script for that?
-
Jul 11, 2007, 11:12 #2
- Join Date
- Jul 2007
- Location
- San Jose, California
- Posts
- 355
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not quite sure what you mean by list but here's on idea
Passing just the individual item in the list
function deleteps(list){
if($list[0] == '(' )
return '';
return $list;
}
-
Jul 11, 2007, 11:16 #3
Well I enter a list of words in a html form and it passes it to a php page which processes it.
apple1
apple2 (grass)
apple3 (water)
apple4
I want it to remove (grass) and (water) parentheses too and leave...
apple1
apple2
apple3
apple4
-
Jul 11, 2007, 11:33 #4
- Join Date
- Jul 2007
- Location
- San Jose, California
- Posts
- 355
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, so how is it stored:
$val1 = $_POST['apple1'];
...
$val4 = $_POST['apple4'];
if this is the case
$val4 = deleteps($_POST['apple4']);
function deleteps(list){
for($i = 0; $i < count($list); $i++)
if($list[$i] == '(' )
return substr($list, 0, $i-1);
return $list;
}
or if its stored in array
for($i = 0; $i < count($array); $i++){
$array[$i] = deleteps($array[$i]);
}
-
Jul 11, 2007, 11:35 #5
- Join Date
- Aug 2005
- Posts
- 453
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$list_r = explode( "\n", $list );
foreach( $list_r as $item ) {
$item = str_replace( "(*)", "", $item );
}
$list = implode( "\n", $list_r );
Computers and Fire ...
In the hands of the inexperienced or uneducated,
the results can be disastrous.
While the professional can tame, master even conquer.
-
Jul 11, 2007, 14:46 #6Code PHP:
<?php $list = array('apple1', 'apple2 (grass)', 'apple3 (water)', 'apple4'); $list = preg_replace('/\\s+\\([^\\(]+\\)/i', '', $list);
Also removes the sapce before "("
-
Jul 11, 2007, 14:53 #7
Actually you don't even need to put the list into an array.
Code php:<?php $list = 'apple1 apple2 (grass) apple3 (water) apple4'; $list = "apple1\napple2 (grass)\napple3 (water)\napple4"; $list = preg_replace('/\\s+\\([^\\(]+\\)/i', '', $list);
Bookmarks