douzhan1935 2013-06-26 16:06
浏览 77

使用PHP解析文本文件中的某些值

I have this raw text file in PHP and I want to get a specific number. Here is the text file:

Bones - Price Guide and Exchange - 2007 Old School RuneScape Jump 
to content Search Advanced Search section: ForumsMembersHelp Files 
Calendar   View New Content      Sign In    Create Account Zybez 
Runescape Help Forums Members OSRS Price Guide 2007 RS Help Premium 
More Runescape Community → OSRS Price Guide → Bones Price Guide: Bones 
The charts and price calculations are currently undergoing a transition. 
Prices may be inaccurate until this is completed, especially for 
less-active items. Please be patient, and notify us of any major problems. 
Recent Trade Price: ~55 GP (rising) Average Sell Offer 50 GP Average Buy 
Offer 60 GP High Alchemy Value 1 GP View more Bones info on 2007rshelp.com 
All Time 90 Days 30 Days 7 Days Latest Offers Offer RS Name Time Info 
Selling 2,000 for 70 GP ea maulsurba11s 5 hours ago pm Buying 25 for 200
 GP ea placation 15 hours ago pm me soon Selling 500 for 60 GP ea iharleyquinn
 18 hours ago Buying 30 for 60 GP ea purple-mlk 18 hours ago Buying 500 for 
60 GP ea og-real-og 24 hours ago Buying 25 for 200 GP ea haxore 32 hours ago
 Buying 25 for 75 GP ea attack-hd 41 hours ago pm me pls ;) Buying 1,000 for
 75 GP ea pupz45 43 hours ago Buying 100 for 200 GP ea i3-a-l-l-e-n 44 hours
 ago Look up a price Post your offer I am BuyingSelling for GP ea. My RS Name
 is Contact me by PMCC Scam Alert Never meet a player in Brimhaven or Entrana. 
Anyone who asks is trying to steal your items. Helpful Links 2007 RuneScape 
Help & Info Bank and Inventory Sales Money Making Tips Join a RuneScape Clan
 Most-Traded Items Nature rune 212 Blue h'ween mask 935,095 Red h'ween mask 
1,135,278 Bow string 88 Yew logs 485 Abyssal whip 1,761,182 Green h'ween mask
 695,655 Yew longbow 740 Prayer potion (3) 6,630 Halloween mask set 2,855,149
 Get Help | API | All Items Created by the almighty No1 1000. Runescape 
Community → OSRS Price Guide → Bones Privacy Policy Change Theme     
IP.Board Graphite (3.3) Thoreau Dark (3.3) Thoreau (3.3) Mark Community 
Read Forums Members Mark all as read Help Community Forum Software by 
IP.Board Licensed to: Zybez Corporation Curse Curse is the #1 Resource 
for core online gamers. Not a Member? Get your Free Account! Sign up for 
Free! Featured SitesMore Guild Wars 2 Guru Guild Wars 2 Guru The latest 
and greatest on Tyria. LoL Pro LoL Pro Dominate with Pro LoL guides. 
MMO-Champion MMO-Champion Keep ahead with the champions of WoW coverage. 
GW2DB GW2DB Explore Tyria with Curse and GW2DB. Browse Core Curse MMO-Champion
 WowStead CurseForge WowAce SkyrimForge SC2Mapster Bukkit Forums LoLPro ExilePro
 Community Minecraft Forum Terraria Online Arena Junkies Guild Wars 2 Guru 
DiabloFans FPS General DarthHater Defiance Forum Wildstar Forums Database
 Guild Wars 2 DB Zybez DarthHater DB Aion Armory WoW Database Marriland Wiki
 Minecraft Wiki Terraria Wiki Wowpedia Skyrim Wiki Wiki SWTOR Dragon Nest Wiki
 Vindictus Wiki Back to Top About Us Advertising Privacy Policy Terms of Service
 Premium Terms of Service Curse Newsletter Jobs at Curse Handcrafted in San Francisco
 & Huntsville Font: Arial | Calibri | Lucida Console | Verdana  
 Font Size: 9px | 10px | 11px | 12px | 10pt | 12pt   Color:   

I want to get the number after "Recent Trade Price:~" and the number will change anywhere from 1-7 digits so it needs to be work with all numbers. I am not sure how to parse the String correctly so I get just the number after "Recent Trade Price"

I have tried using:

$text = $html->plaintext;
$words = explode("Recent Trade Price:", $text);
echo $words[1];

But this gave me everything after so I think I'm halfway there. Could someone please help!

  • 写回答

3条回答 默认 最新

  • du0173 2013-06-26 16:09
    关注

    You could do another explode after that and get the first word, like this:

    $words = explode("Recent Trade Price:", $text);
    $price = explode(" ",$words[1]);
    echo $price[0];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么