Cheeze Posted January 6, 2007 Share Posted January 6, 2007 i have made a script that gets information form a database and displays it to the userbut...the database is writen to by vBulletin forum and the values loo like so:"a:1:{i:4;s:11:"Shplob";}is it possible to make a PHP script that gets rid of "a:1:{i:4;s:11:"";}"so that all i see on the page is "Shplob", but database could look like this:a:1:{i:4;c:7;s:23:"fdgrtgr";}a:1:{i:4;s:78:"ertertferf";}a:1:{i:4;s:56:"sdferetrr";}a:1:{i:8;s:22:"aajoimk";}a:1:{i:4;s:19:"sdfasjk";}a:1:{i:6;s:7:"cwam";}a:1:{i:4;s:4:"serwerwer";}a:1:{i:4;s:55:"rty56yr";}a:1:{i:4;s:7:"easdsdas";}a:1:{i:4;s:44:"jghjjh";}a:1:{i:4;s:2;h:9::"erwer";}a:1:{i:4;s:71:"gftyrt";}a:1:{i:4;s:16:"ghjhj";}so it needs some kind of wildcard or something but evrything i have tried doesn't work Link to comment https://forums.phpfreaks.com/topic/33093-replacing-text/ Share on other sites More sharing options...
coffear Posted January 6, 2007 Share Posted January 6, 2007 The following works:-<?PHP$text = array('a:1:{i:4;c:7;s:23:"fdgrtgr";}','a:1:{i:4;s:78:"ertertferf";}','a:1:{i:4;s:56:"sdferetrr";}','a:1:{i:8;s:22:"aajoimk";}','a:1:{i:4;s:19:"sdfasjk";}','a:1:{i:6;s:7:"cwam";}','a:1:{i:4;s:4:"serwerwer";}','a:1:{i:4;s:55:"rty56yr";}','a:1:{i:4;s:7:"easdsdas";}','a:1:{i:4;s:44:"jghjjh";}','a:1:{i:4;s:2;h:9::"erwer";}','a:1:{i:4;s:71:"gftyrt";}','a:1:{i:4;s:16:"ghjhj";});');foreach ($text as $data){preg_match('/(?:")([\w\d]+)(?:")/',$data,$match);echo "$match[1]\n";}?> Link to comment https://forums.phpfreaks.com/topic/33093-replacing-text/#findComment-154228 Share on other sites More sharing options...
Cheeze Posted January 6, 2007 Author Share Posted January 6, 2007 thank you but with <?PHP$text = array('a:1:{i:4;c:7;s:23:"fdgrtgr";}','a:1:{i:4;s:78:"ertertferf";}','a:1:{i:4;s:56:"sdferetrr";}','a:1:{i:8;s:22:"aajoimk";}','a:1:{i:4;s:19:"sdfasjk";}','a:1:{i:6;s:7:"cwam";}','a:1:{i:4;s:4:"serwerwer";}','a:1:{i:4;s:55:"rty56yr";}','a:1:{i:4;s:7:"easdsdas";}','a:1:{i:4;s:44:"jghjjh";}','a:1:{i:4;s:2;h:9::"erwer";}','a:1:{i:4;s:71:"gftyrt";}','a:1:{i:4;s:16:"ghjhj";});');foreach ($text as $data){preg_match('/(?:")([\w\d]+)(?:")/',$data,$match);echo "$match[1]\n";}?>works with an arraybut i want it to just work with one value at a time so $pies = 'a:1:{i:6;s:7:"cwam";}'and remove all the 'a:1:{i:6;s:7:"";}'s from $pies and then the script would do the same thing again with $pies = 'a:1:{i:4;s:71:"gftyrt";}' Link to comment https://forums.phpfreaks.com/topic/33093-replacing-text/#findComment-154238 Share on other sites More sharing options...
alpine Posted January 6, 2007 Share Posted January 6, 2007 Just ditch the foreach loop[code]<?php$pies = 'a:1:{i:6;s:7:"cwam";}';preg_match('/(?:")([\w\d]+)(?:")/',$pies,$match);echo $match[1]; // prints cwam?>[/code] Link to comment https://forums.phpfreaks.com/topic/33093-replacing-text/#findComment-154260 Share on other sites More sharing options...
coffear Posted January 6, 2007 Share Posted January 6, 2007 yes as alpine states, take it out of the foreach loop. I only kept it in there to show it worked with al of your examples. Link to comment https://forums.phpfreaks.com/topic/33093-replacing-text/#findComment-154267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.