jon121 Posted May 25, 2011 Share Posted May 25, 2011 hi, im a trainee web programmer working mainly with php and mysql but i need abit of help with something. basically i use a script to create me thousands of images at a time with individual names and use the $_GET['make'] code in the <img src> to pull the right image onto the right page. the problem i have is that in the database the model names are plural and i wanted singular image names for seo purposes so i wrote this to get around the prblem: $model_name = substr_replace($_GET['model'] ,"",-1); only thing is that if the plural of something ends in 'ies' ie. 'bodies' i want it to find the image 'body'. how do i add to this code to basically say: if $model_name ends in 'ies' replace with 'y' any suggestions are welcome, thanks. Link to comment https://forums.phpfreaks.com/topic/237427-ammature-substr_replace-help-needed/ Share on other sites More sharing options...
jon121 Posted May 25, 2011 Author Share Posted May 25, 2011 UPDATE TO MY LAST POST the same situation, but this is the code im working with: <?php $model_name = rtrim($_GET['model'], 'S'); $nonplural_model = str_replace("IES", "Y", $_GET['model']); ?> the thing i cant get my head round is simply how to say: if ($_GET['model'] ends with an S) { use the model name } if ($_GET['model'] ends with IES) { use nonplural } im know im just being thick but i just cant remember the string functions to check if the last letter is an S or IES and how to apply it to that if statement. thanks again Link to comment https://forums.phpfreaks.com/topic/237427-ammature-substr_replace-help-needed/#findComment-1220078 Share on other sites More sharing options...
Fadion Posted May 25, 2011 Share Posted May 25, 2011 You can get the last letter with: <?php $s = 'some text'; echo $s[strlen($s)-1]; //will output: t ?> and you can find if the last 3 characters are "ies" with: <?php $s = 'bodies'; if (substr($s, strlen($s) - 3) == 'ies') { echo 'Ends with: ies'; } ?> Not sure if any word that plural makes "ies" and with "y". Anyway if it isn't for anything really important, it doesn't matter much. Link to comment https://forums.phpfreaks.com/topic/237427-ammature-substr_replace-help-needed/#findComment-1220088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.