I have a sample code here
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
<li>I</li>
<li>J</li>
as you can see i am trying to save into session the letter to be sent into sample.php. But even if i press 'B' what gets sent over to the sample.php is 'J' (the last letter) . tried clicking the other letters too its always 'J'.
can anybody help on what i am doing wrong?
Thank you very much
Try this
A</li>
A</li>
A</li>
It’s because your PHP code run and return the HTML output to your browser.
Because of that, all of them are ‘J’.
For solve the problem use code like this:
<li><a href=“sample.php?v=A”>A</a></li>
<li><a href=“sample.php?v=B”>B</a></li>
<li><a href=“sample.php?v=C”>C</a></li>
And you can get v value in your sample.php with this code:
<?php
$linkv=$_GET[“v”];
If ($linkv==“A”)
{
//write your code here
}
If ($linkv==“B”)
{
//write your code here
}
If ($linkv==“C”)
{
//write your code here
}
?>
Related
I have following text
<h2>Subjects</h2>
<ul>
<li><a href='http://isbndb.com/subject/transfer_pricing'>
Transfer pricing</a></li>
<li><a
hef='http://isbndb.com/subject/intangible_property_valuation'>
Intangible property -- Valuation</a></li>
</ul>
the numbers of <li> .. </li> could be variable.
Can anyone tell me the regex to get
Transfer pricing
Intangible property -- Valuation
it might be done with preg_split, but I have no glue how the regex should be.
Thanks a lot.
Try some thing like this:
$output = "<h2>Subjects</h2>
<ul>
<li><a href='http://isbndb.com/subject/transfer_pricing'>
Transfer pricing</a></li>
<li><a
hef='http://isbndb.com/subject/intangible_property_valuation'>
Intangible property -- Valuation</a></li>
</ul>";
preg_match_all("li><a href='(.[^>]*)>(.[^<]*)</",$output , $array_check);
print_r($array_check);
This is my first question.
I'm building a simple dynamic menu using <li>
I'm working on a PHP based CMS (Kirby)
Kirby has predefined PHP functions (helpers)
I'm trying to output a <li> for each page on the website:
<li class='active'><a href='page1'></a></li>
<li><a href='page2'></a></li>
<li><a href='page3'></a></li>
...
Im using a PHP function e($condition, $value) to style the menu item only if that page isOpen()
// I need help here
<?php
foreach ($pages->visible() as $p):
echo "<li" . e($p->isOpen(), ' class="active"') . "><a href='" . $p->url() . "'></a></li>";
endforeach;
?>
The function is working but the css part class="active" is printing OUTSIDE the <li> on the final code
class="active"
<li>...</li>
<li>...</li>
<li>...</li>
I had this previous code that worked fine, but since i'm using display: inline-block the menu had spaces betwes each block, since the following code was placing each <li>in a new line.
// This code works
<?php foreach($pages->visible() as $p): ?>
<li <?php e($p->isOpen(), ' class="active"') ?> ></li>
<?php endforeach ?>
The reason i'm rewrinting the code is to remove the white space between the inline: blockelements.
I'm failing to concatenate the string in a way that the function works and print its results inside the <li>tag.
I've searched here and also have read lots of Docs in php.net but nothing worked to me, I'm struggling with this for 2 days.
I'm expecting to learn better how and when to use concatenation and string operators.
The problem is that Kirby's e() function already has the echo in the routine, instead of just simply returning the value.
http://getkirby.com/docs/cheatsheet/helpers/e
If you were to change your output loop to something more like this, echoing separately, you'll get the results in the desired order:
foreach($pages->visible() as $p)
{
echo "<li";
e($p->isOpen(), ' class="active"');
echo "> and the rest of your line </li>";
}
That said, perhaps using e() isn't the most elegant in this case. Maybe try the r() function instead:
http://getkirby.com/docs/cheatsheet/helpers/r
foreach($pages->visible() as $p)
{
echo "<li ".r($p->isOpen(), ' class="active"').">more text</li>";
}
I am trying to pass a variable between two webpages via a url and using php. I am getting the undefined index error.
I have tried multiple ways of doing this and spent the last several hours googling the problem and think the following code should work -- probably just a conceptual error. Am not using ISSET at this point because this is a url pass and it should be set.
The following code is on the passing page:
<DIV>
<ul>
<li> Christmas Eve, 2014 ; </li>
</ul>
</DIV>
The following code is on bulletindisplay.php
<div>
<?php
$link = $_GET['link'];
echo $link;
?>
</div>
Does anyone see my error? Thank you so much for any help.
Remove all spaces inside href attribute:
<DIV>
<ul>
<li> Christmas Eve, 2014 ; </li>
</ul>
</DIV>
Just remove spaces inside your link.
bulletindisplay.php?link=Bulletins/December_24_2014.pdf
Remove all spaces and use below code:
<li> Christmas Eve, 2014 ; </li>
and in php :
if(isset($_GET['link'])) {
$link = $_GET['link'];
echo $link;
}
link = Bulletins/December_24_2014.pdf
//there is a space after link
If you print out $_GET you will get output like this
Array ( [link_] => Bulletins/December_24_2014.pdf )
So
$_GET['link'] !=$_GET['link_']
//$_GET['link'] is not set that's why you got the error
You need to remove the space after link in your URL. And you should be using isset because if link is not present in the query string you will see a PHP error.
1. if(isset($_GET['link'])) {
2. $link = $_GET['link'];
3. echo $link;
4. }
I'm trying to put a menu together where it will sense what page is loaded. This site is not done in a CMS and is straight PHP/HTML code.
I currently have the navigation working for the primary links. There is a dropdown where I am having problems. I need to be able to see if the parent or any dropdown children are active. If one of the children are active. In the example below this is "FAQ" and the children are "FAQ1," "FAQ2," and "FAQ3."
For this example I'm using a CSS state called "active."
<style>
a{color:red;}
.active{color:blue;}
</style>
Here is the script used for the menu. The links for Home, Products, and Contact are working as expected.
<ul>
<li><a href="index.php" id="homenav" <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="active"';?>>Home</a></li>
<li><a href="products.php" id ="prodnav" <?php if (strpos($_SERVER['PHP_SELF'], 'products.php')) echo 'class="active"';?>>Products</a></li>
<li><a href="faq.php" id ="faqnav" <?php if (strpos($_SERVER['PHP_SELF'], 'faq.php, faq1.php, faq2.php, faq3.php')) echo 'class="active"';?>>FAQ</a>
<ul>
<li>FAQ1</li>
<li>FAQ2</li>
<li>FAQ3</li>
</ul>
</li>
<li><a href="contact.php" id ="connav" <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="active"';?>>contact us</a></li>
</ul>
Can I please get some help on how I should be writing this line to let it work the way the others are?
<li>
<a href="faq.php" id ="faqnav"
<?php
if (strpos($_SERVER['PHP_SELF'], 'faq.php, faq1.php, faq2.php, faq3.php'))
echo 'class="active"';
?>
>FAQ</a>
</li>
strpos() only accepts one string per parameter, you can not give it a list.
Try this:
<?php if (in_array(basename($_SERVER['PHP_SELF']), array('faq.php', 'faq1.php', 'faq2.php', 'faq3.php'))) echo 'class="active"';?>
basename() strips the path from the filename, so you only have the pure file name
in_array() then checks if this path is in an array
array() generates an array of strings to be handed over to in_array(). Note that there are 4 separate strings, not one long one as in your code.
Use in_array for this purpose:
if (in_array($_SERVER['PHP_SELF'], array('faq.php', 'faq1.php', 'faq2.php', 'faq3.php')) echo 'class="active"';
http://php.net/manual/de/function.in-array.php
If you don't have any other pages that contain faq, you can simply use:
if (strpos($_SERVER['PHP_SELF'], 'faq') !== false)
Note that I am using !== false as strpos can return 0 when faq is found at the beginning of your string. You should probably use that for your other comparisons too.
Otherwise, go with the in_array solution of #MrTweek.
I would like to only show the text that is before /*SHOW MORE TEXT*/ However I am unsure how to do such a thing because my text is like this:
<ul>
<li>show this</li>
<li>show this</li>
/*SHOW MORE TEXT*/
<li>don't show this</li>
</ul>
I have tried
$texts = explode("/*SHOW MORE TEXT*/", $text);
But the issue with this is then it won't fix the </ul>
How can I fix this small issue?
Just try with Jquery toggle functions it's more easier and faster. Here you find details: http://api.jquery.com/toggle/
Using php you can do this like
<ul>
<li></li>
<?php
if(condition is true){
echo "<li>text will be displayed if condition is true otherwise it will not displayed</li>";
}
?>
</ul>
using javascript you can use
<li style="display:none;">this will not visible</li>
you can use display:none; property for that and later when you need it you can display it using java script.
<li style="display:none;">don't show this</li>
One possible solution is as follows:
Don't include ul tags in the text string, and then use explode and take the first element of array using array[0] and close </ul> tag.