mallen Posted March 24, 2016 Share Posted March 24, 2016 I'm trying to take the value and pick out everything after the trailing slash. I tested and the variable is correct. On the third line I can't figure out how to format it. var_dump($image);// http://somewebsite.com/images/image1.jpg var_dump(substr(strrchr('http://somewebsite.com/images/image1.jpg', '/'), 1)); //image1.jpg var_dump(strrchr(strrchr('$image','/'),1));//getting false Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 If you want to use a variable, it can't be in a single-quoted string. Try var_dump(strrchr(strrchr($image,'/'),1)); Quote Link to comment Share on other sites More sharing options...
mallen Posted March 24, 2016 Author Share Posted March 24, 2016 I am getting boolean false Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 (edited) Ah...the function calls are backwards. Try var_dump(substr(strrchr($image,'/'),1)); Sorry, not backwards. You were calling strrchr() twice. Edited March 24, 2016 by cyberRobot Quote Link to comment Share on other sites More sharing options...
mallen Posted March 24, 2016 Author Share Posted March 24, 2016 Yes still getting boolean false Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 For what it's worth, this worked for me: <?php var_dump(substr(strrchr('http://somewebsite.com/images/image1.jpg', '/'), 1)); $image = 'http://somewebsite.com/images/image1.jpg'; var_dump($image); var_dump(substr(strrchr($image,'/'),1)); ?> Quote Link to comment Share on other sites More sharing options...
mallen Posted March 24, 2016 Author Share Posted March 24, 2016 Ok I am following you. But in your example you assigned a value to $image. But I already have a value to $image. And if I dump it is gives me the string. So I need to do the reverse. $image = 'http://somewebsite.com/images/image1.jpg'; Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 Ok I am following you. But in your example you assigned a value to $image. But I already have a value to $image. And if I dump it is gives me the string. So I need to do the reverse. I just added the $image variable to test the code. What does your current code look like? Note that you'll want to make sure that strrchr() isn't being called twice and the $image variable isn't enclosed with single quotes. Could you also post the line that defines $image? Quote Link to comment Share on other sites More sharing options...
Solution mallen Posted March 24, 2016 Author Solution Share Posted March 24, 2016 (edited) $THEURL = "SELECT Image_URL From ... ect";//the query $image = $wpdb->get_row($THEURL, ARRAY_A);//the variable is dynamic var_dump(substr(strrchr($image,'/'),1)); fails var_dump(substr(strrchr('http://somewebsite.com/images/image1.jpg','/'),1)); gives 'image1.jpg' var_dump($image); // gives 'http://somewebsite.com/images/image1.jpg' I figured it out: var_dump(substr(strrchr($image['Image_URL'],'/'),1)); Edited March 24, 2016 by mallen Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 Does $wpdb->get_row() return a string...or some other type of variable like an array or object? What is the exact output of var_dump($image); It should look something like this, if it's a string: string(40) "http://somewebsite.com/images/image1.jpg" Also, is PHP set to display all errors and warnings? Note that you can add the following to the top of your script during the debugging process: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 24, 2016 Share Posted March 24, 2016 I figured it out: var_dump(substr(strrchr($image['Image_URL'],'/'),1)); I'm glad you figured it out. Note that I marked the topic as solved. If you need anything else, you can start a new topic...or mark this one as unsolved (if it's directly related). Quote Link to comment 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.