Php snippet pulling in full url. I just want relative url
Hello PHP experts,
I am trying to troubleshoot an image link issue. I have sent an email to the developer and he will eventually get back to me. But maybe not quickly.
In the meantime I think I have found the root of the issue.
There is some js in the application that is referencing the various images. But instead of just putting in the relative url it is pulling in the full absolute url. I want the relative url, not the absolute url.
I know next to nothing about php, but I found this snippet in some javascript in his application.
I am thinking that "{path}" is built-in php placeholder code for full url. Perhaps there is some other placeholder other than "{path}" that will give me just the relative path.
However, as I write this question, I just found another snippet. This is a php snippet. And I am thinking that maybe it is controlling the display of the url. Here it is:
What I want is a relative path, such as <img alt="" src="/images/EmployeePhotos/martha.jpg" /></p>
I thought while I wait for the developer to reply I would ask your thoughts here. Of course I have a backup of the files. I thought maybe you can reply quicker than the developer. After all, this is a holiday weekend, isn't it?
I realize this question may be an exercise in futility without the full code from the application, but I am hoping that the snippets of code may offer a clue to a solution from the EE php experts. :)
Below is how I implemented your code. Am not sure if I did it correctly:
defined( '_JEXEC' ) or die;$element_key=$item_params['element_key'];$element_setting=$item_params['element_setting'];$element_attribute=$item_params['element_attribute'];$element_shortcode=$item_params['element_shortcode'];if(strstr($element_setting['image'],"http://")){// REMOVE THE EXPLICIT DOMAIN NAME FROM THE VARIABLE IN THE $element_setting ARRAY AT THE POSITION NAMED 'image'$image_url = str_replace('http://www.blahblah.edu/', '../', $element_setting['image']);}// THE $image_url VARIABLE WILL BE INJECTED INTO THE HTML DOCUMENT BELOW?><h5><?php echo $element_attribute['name'];?></h5><div style="max-width:300px;"><img src="<?php echo $image_url;?>"/></div>
If this doesn't remove the domain name, there are a few other possibilities. One is that this is not the code that generates the <img> tag. The other is that the domain name is not spelled correctly, or contains HTTPS instead of HTTP, etc.
defined( '_JEXEC' ) or die;$element_key=$item_params['element_key'];$element_setting=$item_params['element_setting'];$element_attribute=$item_params['element_attribute'];$element_shortcode=$item_params['element_shortcode'];// REMOVE THE EXPLICIT DOMAIN NAME FROM THE VARIABLE IN THE $element_setting ARRAY AT THE POSITION NAMED 'image'// THE $image_url VARIABLE WILL BE INJECTED INTO THE HTML DOCUMENT BELOW$image_url = str_ireplace('http://www.blahblah.edu/', '../', $element_setting['image']);?><h5><?php echo $element_attribute['name'];?></h5><div style="max-width:300px;"><img src="<?php echo $image_url;?>"/></div>
Below is how I implemented your code. Am not sure if I did it correctly:
Open in new window
I think I did something wrong because below is the result:
Open in new window
Basically it did not remove the http://www.blahblah.com.
If it looks right I will paste it back in. But please double check my implimentaiton when you have a chance.
Thanks
Rowby