gibigbig Posted June 22, 2010 Share Posted June 22, 2010 I have a string: $string = 'this/is/a/directory/image_id5_XX.jpg'; the XX can be any two numbers, i need a pice of code that will display the above string exactly REGARDLESS of those two numbers XX please help me >< Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/ Share on other sites More sharing options...
radar Posted June 22, 2010 Share Posted June 22, 2010 since thats a string and the numbers will be changing (from the sounds of it) a simple echo should display the data. Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075711 Share on other sites More sharing options...
gibigbig Posted June 22, 2010 Author Share Posted June 22, 2010 no you misunderstood me ok there are these files in a directory: file_id1_98.jpg file_id2_43.jpg file_id3_22.jpg file_id4_11.jpg i have the id from another variable $id. i want to display the image where $id = the id from the image name regardless of the XX number echo '<img src="dir/file_id'.$id.'_XX" />'; i dont know what to put in XX in the above php box so that the script will output the image with the desired id set in $id Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075716 Share on other sites More sharing options...
kenrbnsn Posted June 22, 2010 Share Posted June 22, 2010 Is there only one file per file_id? If so, I would use the glob function to get the file to display: <?php list($file) = glob('dir/file_id' . $id . '_' . * . '.jpg'); echo '<img src="$file" />'; ?> Note: not tested Ken Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075722 Share on other sites More sharing options...
gibigbig Posted June 22, 2010 Author Share Posted June 22, 2010 Parse error: syntax error, unexpected '*' in /filexxxx on line 97 i replaced my real file name and its dir with filexxxx for security Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075729 Share on other sites More sharing options...
radar Posted June 22, 2010 Share Posted June 22, 2010 I do believe the star doesnt belong outside of quotes as it is not a string so remove the ' . and . ' before and after the * respectively and give it a try again. Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075732 Share on other sites More sharing options...
gibigbig Posted June 22, 2010 Author Share Posted June 22, 2010 its ok guys i fixed it myself seems this mystery number was the "avatar revision" number which is stored in the database in the user table. thanks for your quick responses. <3 phpfreaks.com Link to comment https://forums.phpfreaks.com/topic/205575-simple-string-error/#findComment-1075738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.