PHP truncates parameters from inside an anchor tag whenever I build the code in a PHP function, and use a PHP variable for the href value.
NOTE: While writing this up, I had a brain flash and SOLVED my own problem. I will put the problem and solution here in case others find it useful.
BACKGROUND: I'm building a quasi-mega-menu using jQuery and the modal.js plugin of Bootstrap. Everything worked fine, with the menu button triggering the modal, which displays the HTML code I created for the megamenu, along with a dozen or more page links on that menu. The page links worked fine.
Then I decided to add tooltips to the page links to give visitors a brief description of each page. I did this by adding the CLASS and TITLE attributes to the anchor tag for the link. And this part also worked just fine.
Then, to clean up the links, I put the text of the TITLE attribute into a PHP variable. That also worked just fine.
One of the operational anchor links at the time looked like this:
<a href="cleanscans.php" class="tooltip-test" title="<?php echo($TTClSc); ?>">Cleaning Scans</a>
Finally, I wanted to make it even easier to add links to the list, so I built a PHP function to build the line above, passing in two parameters - the stem filename of the page being called and the text for the link:
function BuildMenuItem($Pageroot, $MenuText)
The function worked perfectly, EXCEPT it always truncated (cut off) all parameters after the closing quote of the href="" statement. In other words, the CLASS and TITLE parameters never made it out of the function.
This was driving me bonkers, and I couldn't figure out why this was happening. I went over it a dozen times, and couldn't figure it out, and that's when I decided I had to come here for help.
As I began writing this posting, it occurred to me that anchor parameters don't need to be furnished in any particular order, so if the function truncates everything after the href, why not put class and title before it?
So I tried it, and VOILA! It Worked! My function now very nicely provides new menu links on demand, complete with tooltips. Like this:
<?php echo BuildMenuItem("procedures", "Procedures") ?>
<?php echo BuildMenuItem("pdftools", "PDF Tools") ?>
The only caveat is I have to name my tooltip text variables with $TT concatenated to the stem file name.
Here's an example of the output of that function, from the Procedures call (first line above):
<a class='tooltip-test' title="$TTprocedures" href="http://www.mywebsitename.com/procedures.php">Procedures</a>
But I'm still flummoxed as to WHY this problem occurred. The function to build the above statement will truncate all the parameters after HREF, but they work fine if listed before.
Any clues why?