Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need Help Deleting Unwanted Text
Old 09-02-2007, 07:50 AM Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Here is an example of what i would like to do:

I have some text

laosmsne Colchester 2 1 Manchester United askssa
laosmsne Cardiff 0 1 Plymouth Argyle askssa

is there a way to delete everything except numbers and Colchester(and rest of the footballs teams). Can i strip tags aswell like <a> etc?

I would like the final result to be:


Colchester 2 1 Manchester United
Cardiff 0 1 Plymouth Argyle

Last edited by evans123; 09-02-2007 at 08:02 AM..
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 09-02-2007, 08:38 AM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i would think so...

first of shove all that into a variable
PHP Code:
$text 'laosmsne Colchester 2 1 Manchester United askssa
laosmsne Cardiff 0 1 Plymouth Argyle askssa'
;
 
$text striptags($text); // removes HTML
 
$text str_replace("laosmsne"""$text); //should replace all laosmsne with nothing
 
$text str_replace("askssa"""$text);
 
echo 
$text
This should do it, you can do into a bit more complicated way, if you want to use this on a larger scale with more word u want removed.

like you could have a array which has all football teams in, and tell it to remove everything except the football teams and numeric data.

Talkupation Apprieciated

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-02-2007, 08:52 AM Re: Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
could you help me make the array one cuz thats what i really want. but ive dun dun any arrays.

talkupation on its way!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-02-2007, 08:58 AM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Lol i knew you would want the more compluicated one

im actually gonna have to thing about this!

edit: im writing this, and i have gone blank

i can think how to remove the defined stuff in the array but i cant think how to remove everythign except the array :s

ill post the script in a bit when i figured out the bets way to do it
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE

Last edited by dansgalaxy; 09-02-2007 at 09:06 AM..
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-02-2007, 12:11 PM Re: Need Help Deleting Unwanted Text
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
I came up with this rather quick. So sorry if it's not that good.

Code:
<?php
$arr1 = array('laosmsne', 'Colchester', '2', '1', 'Manchester United', 'askssa');
$arr2 = array('laosmsne', 'Cardiff', '0', '1', 'Plymouth Argyle', 'askssa');

$arr_split1 = array_slice($arr1, 1,4);
$arr_split2 = array_slice($arr2, 1,4);

for ($i = 0, $num = count($arr_split1); $i < $num; $i++) {
  print " $arr_split1[$i]\n";
}

print("<p>");

for ($i = 0, $num = count($arr_split2); $i < $num; $i++) {
  print " $arr_split2[$i]\n";
}
?>
joder is offline
Reply With Quote
View Public Profile
 
Old 09-02-2007, 12:17 PM Re: Need Help Deleting Unwanted Text
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
What I would do is compile an array/list of Football teams and then use a regex to filter out the scores. this means that the junk text at either side can be filtered regardless of what it is.

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 09-02-2007, 12:23 PM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I been trying to get this, (and been asking about it)

i think what you were saying is basically what i was doing... or trying to do.

im thinking along maybe this kind of logic:

PHP Code:
<?php
// Load text into a variable this can be done in a few ways easies being this.
$text 'laosmsne Colchester 2 1 Manchester United askssa
laosmsne Cardiff 0 1 Plymouth Argyle askssa'
;
// Set teams
$teams = array(
   
"Colchester"
   
"Manchester United"
   
"Cardiff"
   
"Plymouth"
   
"Swindon!"
   
"Portsmouth"
   
);

$text str_replace(!$teams || is_number""$text);
echo 
$text;
?>
but obviously that dont actually work...

just need a way to remove everything which isnt in the $team array or a number
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-02-2007, 12:48 PM Re: Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
ye thats what i wanna do is find a away from an array to say if its not equal to anything in the array delete it!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-02-2007, 01:16 PM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
unfortunaly tho str_replace dont do things like !$team (Not teaam as in it dont equal that)

Where are you getting this text from to begin with it might be easier o script that way.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-02-2007, 04:15 PM Re: Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
well i imploded it to a $var but it also contains html code etc.

PHP Code:
implode('',file('http://www.sportinglife.com/football/popup/football365/latest_scores.auto?/opt/ASFapache/htdocs/site/football/live/latestscores/cc_champ.insdat')) 
how would i make a regex?
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-02-2007, 05:34 PM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
might be easier to get it from the HTML, im too tired and have coursework to writte something to do it.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-03-2007, 12:35 PM Re: Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
the text is not static its dynamic! Its football scores it updates when someone scores.
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-03-2007, 02:00 PM Re: Need Help Deleting Unwanted Text
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
yes, but like the infomation is surrounded in the same tags so like you could write a script to get the infor between blah X blah X
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-03-2007, 03:41 PM Re: Need Help Deleting Unwanted Text
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
here might be an idea! how do u use arrays? and would this work! convert whole document to lowercase then str_replace all footballs teams etc and delete everything which isnt capital using the regex?
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Reply     « Reply to Need Help Deleting Unwanted Text
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.59442 seconds with 12 queries