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
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);

Link to comment
Share on other sites

I want to create a table $y that contains anything that matches with the pattern /<img src\=[\"](.*?)[\"] (.*?)>/si'..Then convert any value of the table into string so as to check if the value contains a specific phrase..That's way i'm using substr().

Link to comment
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);

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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()..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.