playwright Posted July 14, 2010 Share Posted July 14, 2010 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?? Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/ Share on other sites More sharing options...
kenrbnsn Posted July 14, 2010 Share Posted July 14, 2010 Can you give us an example of the input and the results you want? Ken Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085880 Share on other sites More sharing options...
bh Posted July 14, 2010 Share Posted July 14, 2010 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 Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085882 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2010 Share Posted July 14, 2010 Do you want <?php $str - implode('',$y[$i]); ?> I'm still not seeing what you're trying to do. Ken Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085884 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 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(). Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085887 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 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().. Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085891 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2010 Share Posted July 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085894 Share on other sites More sharing options...
bh Posted July 14, 2010 Share Posted July 14, 2010 @kenrbnsn: and i dont understand this: $new = substr($keys,30,7); why the fix 30 whether ? @playwright: you should specify the task. Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085900 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 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().. Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085906 Share on other sites More sharing options...
bh Posted July 14, 2010 Share Posted July 14, 2010 Then why dont you get only the images src's contain? Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085914 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 Which pattern should i use to do so?? Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085917 Share on other sites More sharing options...
playwright Posted July 14, 2010 Author Share Posted July 14, 2010 Problem solved..I just needed to use foreach ($y[$i] as $img){}.. Quote Link to comment https://forums.phpfreaks.com/topic/207720-convert-arrays-values-to-string/#findComment-1085930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.