Jump to content

Replacing Text


Cheeze

Recommended Posts

i have made a script that gets information form a database and displays it to the user
but...
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

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

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 array
but 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.