KillerBeeZ Posted June 3, 2012 Share Posted June 3, 2012 is there a function to take a part of a string and add to it? for example, in my database I have the addresses stored for several images. I'm making a racing game that shows these images for the cars while racing. The problem is resizing the images in html only shrinks the physical dimensions but the image still takes the same amount of space, like 200k or something depending on the image. I have thumbnails for all of the images and the name of the file is exactly the same as the original except with a TN- added to the front of the file name. I could add that fairly easily except that the folders are different for the images So, what I'd like to do is to add a TN- in the middle of a string. <div align=\"center\"><img src=\"$car1image[0]\" height=\"50\"></div> $car1image[0] = "http://www.ctlinx.com/piwigo/upload/2012/05/24/20120524171350684011fb.jpg" will need to be changed to $car1image[0] = "http://www.ctlinx.com/piwigo/upload/2012/05/24/TN-20120524171350684011fb.jpg" (these addresses are not static, they are dynamic, I made them static here as an example) Is this possible? Is there a better way to resize images on the fly? or do I have to add all the thumbnails to the database too (keeping in mind there are at present over 3000 images and that's just Dodge, Chevy and a few Audi's)? Quote Link to comment https://forums.phpfreaks.com/topic/263571-manipulate-a-string/ Share on other sites More sharing options...
freelance84 Posted June 3, 2012 Share Posted June 3, 2012 I you are creating dynamically: $car1image[0] = "http://www.ctlinx.com/piwigo/upload/2012/05/24/20120524171350684011fb.jpg" How are you doing so? Are you joining strings together? Do you know already the file name of the .jpg, ie just the file name without the path before it? Quote Link to comment https://forums.phpfreaks.com/topic/263571-manipulate-a-string/#findComment-1350786 Share on other sites More sharing options...
Barand Posted June 3, 2012 Share Posted June 3, 2012 if path is fixed length <?php $str = "http://www.ctlinx.com/piwigo/upload/2012/05/24/20120524171350684011fb.jpg" ; $new = substr($str, 0, 47) . 'TN-' . substr($str, 47); echo $str .'<br />'; echo $new; ?> Quote Link to comment https://forums.phpfreaks.com/topic/263571-manipulate-a-string/#findComment-1350788 Share on other sites More sharing options...
KillerBeeZ Posted June 3, 2012 Author Share Posted June 3, 2012 thank you so much, that was perfect and you my friend are a genius with php oh and Freelance, the path and file name are all saved as one big string in sql as the people entering in the data upload the image, then just copy the path in their browsers address bar to enter into the database. Quote Link to comment https://forums.phpfreaks.com/topic/263571-manipulate-a-string/#findComment-1350840 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.