Passing URL parameter to link on page - url

I am trying to grab a parameter from a webpage and insert it into a URL link on that same page but am having problems with the syntax.
So, for example, the webpage is www.website.com?src=mm
Currently the code on the page that does not pull in the parameter is
<?php echo "<A HREF='http://www.website2.com?offer=AAt&sub1=422'><B>Click Here</B></A><BR>" ?>
I would like to include that "mm" parameter at the end of the URL so the final URL is:
http://www.website2.com?offer=AA&sub1=422&sub2=mm
I tried the following but does not work:
<?php echo "<B>Click Here</B><BR>" ?>
Any ideas on how to get this to work? Thanks

Your code doesn't even compile:
Parse error: syntax error, unexpected 'http' (T_STRING), expecting ',' or ';' in /var/www/html/ImagePT/test.php on line 1
it has to be
<?php echo '<B>Click Here</B><BR>'; ?>
but since I'm just in the mood to give you some further advice:
You don't have to write HTML in uppercase, it's rather unusual (not impossible, but you don't see it very often) - then this script is horrible, when the $_GET['src'] variable is undefinied, therefore I'd check if it is set and then modifiy the URL accordingly. So my advice would be to use the following:
<?php
if(isset($_GET['src']))
{
echo '<b>Click Here</b></br>';
}
else
{
echo '<b>Click Here</b></br>';
}
?>

Related

Change youtube shortened url value in iframe

I am using advanced custom filed wordpress plugin to create a meta tag called youtube URL...
When some one put the video url in shorter format like this https://youtu.be/H-30B0cqh88
Then the iframe I put to show the video doesn't work cause iframe doesn't work with shorter version of url
rather it needs real url as a source.. My iframe code is as below
">
How can I achive this.. Let me show you how I want to achieve this..
I am not that expert on php so please give me the full working code..
<?php
the_field("listing_video_1") == $got_url_from_user_input
if $got_url_from_user_input == https://youtu.be/H-30B0cqh88 in this format
$actual_URL= replace above url to https://youtube.com/embed/H-30B0cqh88
?>
How can I achieve this please.
Thanks in advance
Here's a simple way to use preg_replace to accomplish what you are trying to do:
<?php
// SET OUR DEFAULT URL
$got_url_from_user_input = 'https://youtu.be/H-30B0cqh88';
print "\nSTARTING URL: ".$got_url_from_user_input;
// DO THE REPLACE AND PRINT OUT THE FINAL RESULT
$actual_URL = preg_replace('~https://youtu\.be/([-A-Z0-9]+)~i', 'https://youtube.com/embed/$1', $got_url_from_user_input);
print "\nFINAL URL: ".$actual_URL;
There's not much magic here, so let me run down it quickly:
https://youtu\.be/ - Look for this pattern exactly. We escape the dot with a backslash so it finds a literal dot and not any character.
([-A-Z0-9]+) - This is just your basic character class matching any dash, letter or number, occurring at least one time. We put it in parenthesis so that we it will be saved in $1 and we can plug it into our final url.
Here is the above code in a working demo you can take a look at:
http://ideone.com/zECA2e
You can just use php str_replace() function as in following code :
<?php
$actual_url = str_replace('https://youtu.be/', 'https://www.youtube.com/embed/', $got_url_from_user_input);
echo $actual_url;
?>
str_replace() will replace youtubes short url with embade url.

enter a specific object value

i'm using zendframwork 2 , i implement the album exemple in the official documentation
http://framework.zend.com/manual/2.1/en/user-guide/overview.html#the-tutorial-application (so in my model folder i have Album.php and AlbumTable.php) and all works fine , i just want to make a small modification :
i want to have acces to the third element in album . in the index.phtml view (originally i have this code )
<?php foreach ($albums as $album) : ?>
<?php echo $this->escapeHtml($album->title);?>
<?php echo $this->escapeHtml($album->artist);?>
<?php endforeach; ?>
i tried things like
<?php echo $this->escapeHtml($album->title[3]);?>
<?php echo $this->escapeHtml($album[3]->title);?>
but i always get this error
( ! ) Fatal error: Cannot use object of type Auth\Model\Album as array in C:\wamp\www\zf2-album\module\Auth\view\auth\auth\index.phtml on line 14
any help please ?
thanks every one
Do you need ONLY the third one? Then write your Query to be more efficient ;) For all other cases, since you are working with a Zend\Db\ResultSet\ResultSet, which uses Iterator you have different options.
The first one would be to still iterate through the fieldset like
while ($albums->key() != 3) {
$albums->next();
}
$album = $albums->current();
The alternative would be to simply convert the ResultSet into an array
$myAlbums = $albums->toArray();
$album = $myAlbums[3];
Depending on how big your ResultSet is and how many entries you really need, either Solution may be faster for you. Guess you have to test that one ;)

magento display request url

i wanted to display the module,controller,method being called
i thought that the cms module found in the
app\code\core\Mage\cms\
calls the IndexController.php and uses the IndexAction method .since it is the default page url.
but when I tried to echo out something inside the IndexAction method .nothing comes out. I even tried to call it manually and it still redirects to the home page.
localhost/magento/index.php/cms/index/index/
am i doing it right?
how can i display the request url being called in magento?
I was looking for this also, here's how to do it:
echo Mage::helper('core/url')->getCurrentUrl();
Hi you could try to output the following
<?php
echo Mage::app()->getRequest()->getModuleName();
echo Mage::app()->getRequest()->getControllerName();
echo Mage::app()->getRequest()->getActionName();
?>
Not tested but maybe you can do something like this
<?php
echo Mage::app()->getRequest()->getRequestUri();
?>
Hope this helps
greetings
I needed the URL segments, so I used this:
function getUrlSegment($i) {
$_baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$_currentUrl = Mage::helper('core/url')->getCurrentUrl();
$_path = str_replace($_baseUrl, '', $_currentUrl);
$_segments = explode('/', rtrim($_path, '/'));
return $_segments[$i];
}
// Would get 'store' if URL: http://example.com/store/product/123
$root = getUrlSegment(1);
You might be getting 'headers already sent' warnings in your log files using an echo in the controller. Instead of using echo use Mage::log, e.g.
Mage::log('My request url is: '.$requestUrl);
The log line should appear in the /var/logs/system.log file.
The route cms/index/index is only ever used for the home page. Other standard pages like "no-route" and "enable-cookies" are optionally handled by specific actions on the IndexController. The remaining pages are handled by Mage_Cms_PageController::viewAction() instead. Try the path cms/page/view/id/customer-service to see. The parameter is id and so the next term customer-service is the page identifier which you set in the admin as "URL Key".

php.ini path inside code

To get php.ini path i simply run
<?php
phpinfo();
?>
what is the way to get the php.ini path to show to the user. without showing the whole phpinfo file.
phpinfo(INFO_GENERAL) would be smaller
http://us3.php.net/manual/en/function.phpinfo.php
If you have PHP 5.2.4 or later, you can simply use the php_ini_loaded_file() method which returns the path as a string.
If you don't have that version, here's one way.
ob_start();
phpinfo(INFO_GENERAL);
$data = ob_get_contents();
ob_end_clean();
$lines = explode("\n", $data);
foreach($lines as $line){
list($name, $value) = explode("=>", $line);
if (trim($name) == 'Loaded Configuration File') break;
}
echo $name . ' - ' . $value."\n";
That simply prints:
Loaded Configuration File -
/etc/php5/cli/php.ini
Of course you could use a regex match or something fancier like that if you wanted to.

Symfony: any way to show the global errors only if there isn't any field error?

in a form if there is a field and a global error both messages are showed.
I would like to show the global errors only if there isn't any field error.
Any idea?
This snippet should do the job
<?php if (0 == ( count($form->getErrorSchema()->getErrors()) - count($form->getErrorSchema()->getGlobalErrors()) ) ):?>
<?php echo $form->renderGlobalErrors()?>
<?php endif?>

Resources