make phone number clickable to dial screen on mobile? - php

How can i make a phone number that's being echoed in php from mysql database?
I'm new to php and mysql and still learning, please can someone explain or show me how to make a phone number clickable to go to the dialing screen on a mobile.
Here's the code im using below, i some how need to adapt the hyperlink aroung my '
<?php
$user_type_set = user_type_profile();
while ($user = mysql_fetch_array($user_type_set)) { ?>
<div class="contact-buddy"></div><div class="contact-buddy2"></div>
<div class="contact_details_phone"><p><strong>Phone: <div class="phone_font"><strong><?php echo $profile['contact_number'] ?></strong></div></div></p>
<div class="contact_details_email"><p><strong>Email: <?php echo $profile['public_email'] ?></strong></p></div>
<? } ?>

This should definitely work on iphones, but I believe it would work for androids as well. Your php should output as it's final product something similar to:
1-800-555-5555

If you want to make the phone number returned by <?php echo $profile['contact_number'] ?> clickable then you can use a straight HTML code block with inline PHP:
<?php echo $profile['contact_number']; ?>
Or clean it up a bit with this PHP:
<?php
$phone = $profile['contact_number'];
echo "$phone";
?>
Whichever method you want.

Related

How can I use a php parameter in HTML markup?

So I have tried researching this before jumping into asking this question. Given that I have an index.php, and a cookie which stores the username, saved as $name, most answers tell me its simple to do this:
echo '<h3>'.$name.'</h3>'
But this doesnt work for me, and I assume its because im doing strange syntax for an if statement first, and I want to use the parameter within this if statement. My exact code looks more like this:
<?php
//store the cookie
$name=$_COOKIE['user'];
//check that it is set
if(isset($_COOKIE['user'])):
<section id="login">
<h1> Welcome</h1>
echo '<h3>'.$name.'</h3>';
</section>
else: //prompt to login
endif;
?>
It is meant to show a welcome message to a user that is logged in, adressing them by name, otherwise prompt the user to login.
So my question is: Why doesn't the parameter reflect at all? (shows nothing when the page is loaded) and How can I get this to work as intended?
ps. Please don't worry about the security risk of using cookies to do this etc. It is purposefully vulnerable.
pps. I am 100% sure the cookie is set, I viewed it with a cookie browser.
It doesn't work because the previous two lines are invalid PHP so it would throw an error and stop working.
If you want to use the echo approach then the correct syntax would be:
echo '<section id="login">';
echo '<h1> Welcome</h1>';
echo '<h3>'.$name.'</h3>';
It is important to never insert external data as if it were raw HTML. This can render you vulnerable to XSS attacks. Treat the input as plain text and convert it to HTML before outputting it into an HTML document.
$name_html = htmlspecialchars($name);
echo '<section id="login">';
echo '<h1> Welcome</h1>';
echo '<h3>'.$name_html.'</h3>';
You can make the code easier to read by using variable interpolation:
$name_html = htmlspecialchars($name);
echo '<section id="login">';
echo '<h1> Welcome</h1>';
echo "<h3>$name_html</h3>";
And when outputting large chunks of HTML, it is easier to just drop out of PHP mode entirely:
$name_html = htmlspecialchars($name);
?>
<section id="login">
<h1> Welcome</h1>
<h3><?=$name_html?></h3>
<?php
Aside
Check to see if the cookie is set before you try to use it, not afterwards!
if(isset($_COOKIE['user'])):
$name=$_COOKIE['user'];
you should use php + html like this:
<?php $var = 'my string'; ?>
<?php if ($var == 'my string') : ?>
<h1><?php echo $var; ?></h1>
<?php endif;?>
this breaks up the if statement, allowing you to add html inbetween the conditional statement without having to echo and html from php
You should post any errors you get - But your can't just write html inside php, without either echoing it out, or ending the php for a while.
<?php
//store the cookie
$name=$_COOKIE['user'];
//check that it is set
if(isset($_COOKIE['user'])):?>
<section id="login">
<h1> Welcome</h1>
<?php echo '<h3>'.$name.'</h3>'; ?>
</section>
<?php else: //prompt to login
endif;
?>
To display HTML code only if a php statement is true, just close the php tag right after you have opened the if statement and then put your HTML code between.
<?php
//store the cookie
$name=$_COOKIE['user'];
//check that it is set
if(isset($_COOKIE['user'])) {
?>
<section id="login">
<h1> Welcome</h1>
<h3><?php echo $name; ?></h3>
</section>
<?php
} else {
echo 'Please login';
}
?>

echo php variabel in HTML(wordpress)

I have created a custom wordpress post type everything works but my client asked me to insert a function that doenst show the button if the link field is empty that is also working but when I want to display the tekst or link the part where the php is inserted just doesnt shows up what am I doing wrong
I am able to get the data on other parts of this php file but not in this part of the page
<?php
$linktitle = $day_aray=get_field("under_shoe_button_title");
$linkexist = get_field("under_shoe_button_link");
echo($linktitle);
if (empty($linkexist)) {
echo '<html> <p></p></html>' ;
}
else {
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html> <?php echo($linktitle); ?> <html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
}
?>
If you would look carefully, you would notice, that you are echoing a string where, inside the string, you are trying to echo again. Even with little programming knowledge, you should understand, that it is not logical to do that.
The same goes for php opening <?php tag. You opened the tag at start of the page and later on, inside a string, you are trying to open it again. This does not work.
Instead, close the string (or escape it) and then add the echo option.
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html>';
echo($linktitle);
echo '<html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
And please, read the comments to you question and learn basic HTML
There are so many things wrong in your code
Firstly you are using echo inside echo you should use concatenation instead.
so you want to echo it like this
echo '<your html code>'.$linktitle.'<your other html code>';
Also your html code is wrong coz u are using many html tags.

php html page - take the URL, do a search replace on it, then output the result into the html

Hi I need a simple way with inline PHP to search/replace the URL string, then output the result into the HTML
Our checkout cart redirects people to our post-purchase page, and something like the following ends up in the URL bar:
http://example.com/postpurchasepage.php?amount=$9.99&firstname=Billy&lastname=Bob
More often, based on the browser, they end up with this in their URL bar:
http://example.com?amount=%249.99&firstname=Billy&lastname=Bob
(converts the $ into %24 )
Yes, the cart sends the $ symbol along inside the parameter value. No I don't want it, nor the %24. So, the challenge is to remove both the $ symbol or the %24 (whichever happens),
Right now I am trying to pull the amount value into the page using <?php echo #$_GET['amount']; ?>
For example:
<p>Hey <?php echo #$_GET['firstname']; ?> !</p>
<p>Thanks for donating <?php echo #$_GET['amount']; ?></p>
However that outputs:
<p>Hey Billy !</p>
<p>Thanks for donating %249.99</p>
I want it to output:
<p>Hey Billy !</p>
<p>Thanks for donating 9.99</p>
(or whatever the amount value is that was passed from the cart, without the $ symbol or the %24)
Like I said, basically I am looking for a way to search the URL bar for whatever I define (multiple 'or' type searching), replace with whatever I define, and output the result into the html
Any help appreciated!
You might be looking for urldecode()
echo urldecode("%24"); // $
Then you can strip off the leading $ (if any):
$string = (strpos($string)===0) ? substr($string, 1) : $string;
Manual: http://php.net/manual/en/function.urlencode.php
There are two ways (or more - depending on your creativity & scenario) to get this done;
If you have access to the value of amount before the redirecting occurs, you can strip off the "$" sign and just send in the numeric value and use it there.
Otherwise, you can get the value on the page, and then as willoller mentioned, urldecode it and you can then strip the any leading character that is not numeric. (Not sure if performance would be an issue but that's what worked for me several times before)
Here's a sample for your code:
<p>Hey <?php echo #$_GET['firstname']; ?> !</p>
<p>Thanks for donating <?php echo #$_GET['amount']; ?></p>
<?php
$Get_Amount = urldecode($_GET['amount']);
// WHILE LOOP = TO VALIDATE IF VALUE IS NUMERIC
while (is_numeric($Get_Amount)==false) {
if (is_numeric(substr($Get_Amount, 0,1))){
// DO NOTHING = First Character Numeric
// Might be an issue if you have characters in between the number
// THIS WILL CAUSE RE-LOOP PROBLEM (Dependent on your scenario)
}else{
// TRIM OFF THE FIRST CHARACTER
$Get_Amount = substr($Get_Amount, 1);
}
}
?>
<p>Thanks for donating <?php echo $Get_Amount; ?></p>
Hope this helps! Good Luck!
OR -----------------------
You can use the preg_replace function like this:
<p>Hey <?php echo #$_GET['firstname']; ?> !</p>
<p>Thanks for donating <?php echo #$_GET['amount']; ?></p>
<?php
$String_Get_Amount = urldecode($_GET['amount']);
// Here you can add the characters that you wanna delete
// You should not delete anything that is not numeric cause then it would even replace the decimal point
$String_Search_For_Pattern = '/[$]/';
// Replace it with nothing
$String_To_Replace = '';
$String_Get_Amount = preg_replace($String_Search_For_Pattern, $String_To_Replace, $String_Get_Amount);
?>
<p>Thanks for donating <?php echo $String_Get_Amount; ?></p>

Why is this XML attribute showing up twice

In PHP i'm using the following code to put a banner at the top of my website.
$eventinfo = simplexml_load_file("eventinfo.xml");
<div id="eventinfo"><?php foreach($eventinfo->children() as $child){ $final = $child["name"]."...<a href='".$child["adr"]."'>more info...</a>"; } ?>
</div>
The XML doc is available at the following: http://eastsidespeedway.raceresults.co/eventinfo.xml
If you go to http://eastsidespeedway.raceresults.co/index.php you'll see that the more info... link is showing up twice. One with the correct link, and the other with a link to the same page (index.php).
Can anyone shed some light on what I'm doing wrong?
Also. If you see anything that I'm doing wrong, or you know something that's easier - let me know! This is my first time using XML/PHP so I'm kinda just wingin it. Haha.
this will work for you
<?php
$doc = new DOMDocument();
$doc->load('http://eastsidespeedway.raceresults.co/eventinfo.xml');
$title = $doc->getElementsByTagName('title');
$link = $doc->getElementsByTagName('link');
//print_r($eventinfo);
?>
<div id="eventinfo">
<?php echo $title->item(0)->getAttribute('name'); ?>
<a href='<?php echo $link->item(0)->getAttribute('adr'); ?>'>More Infoo..</a>
</div>
If you look at your source:
<div id="eventinfo">5/18/2013 - Al Smiley Memorial...<a href=''>more
info...</a>...<a href='http://www.eastsidespeedway.com/dirt.html'>more
info...</a></div>
You've got two hyperlinks- one href is blank meaning that it will redirect to the current page, check your HTML code first to see if you've accidentally duplicated the element, otherwise look at the construction of your string in the php code

Stacking PHP code?

I've done a project that now needs to be changed in order to display one div if a variable is in an array and a different div if it isn't in the array.
Normally I'd just do
<?php $quartermonths = array("February","May","August","November");
if (in_array($month,$quartermonths))
{echo "quarter code in here";}
else
{echo "nonquarter code in here";}
?>
and be on my merry way, however the code I've got already contains a load of html and php code already, which doesn't like encapsulated within another PHP block (as far as I'm aware?)
e.g.
<?php $quartermonths = array("February","May","August","November");
if (in_array($month,$quartermonths))
{echo "Quarter HTML CODE
<?php quarter phpcode ?>";}
else
{echo "Non-Quarter HTML CODE
<?php non-quarter phpcode ?>";}
?>
So my question is, what is the best way to tackle this? Is it simply to do a javascript hide div A when the variable is met and hide divB when the variable isn't met, or is there a better solution?
Thanks
<?php
if (in_array($month,$quartermonths))
{ ?>
Quarter HTML CODE
<?php quarter phpcode ?>
<?php } ?>
split your html code from php code like this.
It sounds like you just want to concatenate the value of quarter phpcode. Let's say it's a single function, quarter_phpcode(). You can just do this:
{ echo "Quarter HTML CODE" . quarter_phpcode(); }

Categories