simonp Posted May 30, 2008 Share Posted May 30, 2008 Hi, I have some code that grabs information from a source that I can't change: $gamerachievements always returns five entries in the following format: <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%60m%2fl4%07%02&compareTo=xxx"><img height="32" width="32" title="Call of Duty 4" alt="" src="http://tiles.xbox.com/tiles/3g/9G/0Wdsb2JgbA9ECgQJGgYfWSpVL2ljb24vMC84MDAwIAABAAAAAP5pD8E=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bhe)j3se4X6z-17&compareTo=xxx"><img height="32" width="32" title="Boom Boom Rocket" alt="" src="http://tiles.xbox.com/tiles/ZP/3f/1Wdsb2JgbA9ECgUAGwEfVlkiL2ljb24vMC84MDAwIAABAAAAAPrw-Xs=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%15%18*iN%0bu&compareTo=xxx"><img height="32" width="32" title="Scene It? LCA" alt="" src="http://tiles.xbox.com/tiles/0g/je/02dsb2JgbA9ECgR8GgMfVlxRL2ljb24vMC84MDAwIAABAAAAAPzxCM0=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bdh-%01%07&compareTo=xxx"><img height="32" width="32" title="GTA IV" alt="" src="http://tiles.xbox.com/tiles/8x/Us/1Wdsb2JgbA9ECgUMGgQfWSlRL2ljb24vMC84MDAwIAABAAAAAPoDFew=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bdh-o%3fy%03&compareTo=xxx"><img height="32" width="32" title="Bully Scholarship Ed." alt="" src="http://tiles.xbox.com/tiles/x3/MQ/1mdsb2JgbA9ECgUMGgQfVl4iL2ljb24vMC84MDAwIAABAAAAAPk-c9g=.jpg" /></a> . . . but I only want to use four of them (so I want to ditch the last link + image) Is this possible? Cheers Simon Link to comment https://forums.phpfreaks.com/topic/107993-solved-trimming-input/ Share on other sites More sharing options...
rajivgonsalves Posted May 30, 2008 Share Posted May 30, 2008 try this <?php $strContent = <<< EOF <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%60m%2fl4%07%02&compareTo=xxx"><img height="32" width="32" title="Call of Duty 4" alt="" src="http://tiles.xbox.com/tiles/3g/9G/0Wdsb2JgbA9ECgQJGgYfWSpVL2ljb24vMC84MDAwIAABAAAAAP5pD8E=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bhe)j3se4X6z-17&compareTo=xxx"><img height="32" width="32" title="Boom Boom Rocket" alt="" src="http://tiles.xbox.com/tiles/ZP/3f/1Wdsb2JgbA9ECgUAGwEfVlkiL2ljb24vMC84MDAwIAABAAAAAPrw-Xs=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%15%18*iN%0bu&compareTo=xxx"><img height="32" width="32" title="Scene It? LCA" alt="" src="http://tiles.xbox.com/tiles/0g/je/02dsb2JgbA9ECgR8GgMfVlxRL2ljb24vMC84MDAwIAABAAAAAPzxCM0=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bdh-%01%07&compareTo=xxx"><img height="32" width="32" title="GTA IV" alt="" src="http://tiles.xbox.com/tiles/8x/Us/1Wdsb2JgbA9ECgUMGgQfWSlRL2ljb24vMC84MDAwIAABAAAAAPoDFew=.jpg" /></a> <a href="http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bdh-o%3fy%03&compareTo=xxx"><img height="32" width="32" title="Bully Scholarship Ed." alt="" src="http://tiles.xbox.com/tiles/x3/MQ/1mdsb2JgbA9ECgUMGgQfVl4iL2ljb24vMC84MDAwIAABAAAAAPk-c9g=.jpg" /></a> EOF; echo implode('</a>',array_splice(preg_split("/<\/a>/",$strContent),0,4)); ?> Link to comment https://forums.phpfreaks.com/topic/107993-solved-trimming-input/#findComment-553505 Share on other sites More sharing options...
simonp Posted May 30, 2008 Author Share Posted May 30, 2008 Thanks Rajiv, I tweaked your code to: $gamerachievements = implode('</a>',array_splice(preg_split("/<\/a>/",$gamerachievements),0,4)) . "</a>"; . . . which worked a treat. Cheers! Simon Link to comment https://forums.phpfreaks.com/topic/107993-solved-trimming-input/#findComment-553532 Share on other sites More sharing options...
Perad Posted May 30, 2008 Share Posted May 30, 2008 What is this? <<< EOF Link to comment https://forums.phpfreaks.com/topic/107993-solved-trimming-input/#findComment-553534 Share on other sites More sharing options...
rajivgonsalves Posted May 30, 2008 Share Posted May 30, 2008 that the heredoc string, you can see it at http://in2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Link to comment https://forums.phpfreaks.com/topic/107993-solved-trimming-input/#findComment-553537 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.