Jump to content

convert arrays values to string


playwright

Recommended Posts

hello!! is there any function that can convert every single value of an array into string??? I tried implode() but i think it converts the whole array into one string..maybe i'm wrong..this is what i'm trying to do..

 

preg_match_all('/<img src\=[\"](.*?)[\"] (.*?)>/si',$x, $y);

$count = count($y;

for ($i=1;$i<=$count;$i++){

$keys = implode("+",$y[$i]);

$new = substr($keys,30,7);

}

 

any ideas??

Link to comment
https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/
Share on other sites

heres the problem:

 

$keys = implode("+",$y[$i]);
$new = substr($keys,30,7);

 

$keys is an array...

so concate $keys elements

 

simple example:

$keys = implode("+",$y[$i]);

$str = '';
foreach ($keys as $key)
{
$str .= $key;
}

$new = substr($str,30,7);

  Quote

heres the problem:

 

$keys = implode("+",$y[$i]);
$new = substr($keys,30,7);

 

$keys is an array...

so concate $keys elements

 

simple example:

$keys = implode("+",$y[$i]);

$str = '';
foreach ($keys as $key)
{
$str .= $key;
}

$new = substr($str,30,7);

 

it gives me an error Invalid argument supplied for foreach()..

So, I tried this example:

<?php
$x = '<img src="x.jpg" width=1 height="1">';
preg_match_all('/<img src\=[\"](.*?)[\"] (.*?)>/si',$x, $y);
?>

Which results in $y containing:

Array
(
    [0] => Array
        (
            [0] => <img src="x.jpg" width=1 height="1">
        )

    [1] => Array
        (
            [0] => x.jpg
        )

    [2] => Array
        (
            [0] => width=1 height="1"
        )

)

 

Please explain using the above output what you're trying to obtain.

 

Ken

I'll be more specific : i Want to grab every :

<img src="blablabla" border="X" alt="" title="X" class="X" /> that exists in the source code..That's why i use preg_match_all(). Then i want to check for every record if in "blablabla" a specific word is contained.Let's say if "smilies" is contained in "blablabla". And "smileys" appears only in 30th position of "blablabla" and that's why i use substr()..

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.