Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Help] [PHP] Variables/Strings

Featured Replies

I'm looking for some help with converting special characters within a string to a different character.

 

Current Code:

<?php echo $use['value'] ?>

 

$use is an array

['value'] is the string within the array

 

I'm taking the data from $use['value'] and using it in a URL. The problem is if $use['value'] is something like "Home Projects & Hobbies" the URL gets messed up; it will look like /Home%20Projects%20&%20Hobbies.

 

So, if possible, I want to write a little script that will take the spaces of the string and convert them into "-" and take the "&" symbol and convert it into "and".

bike.png

Suggest a poll for Tip.it - Here!

  • Author

I'm using a php loop that creates the links here:

49667.png

 

Code that makes the links:

<a href="<?php echo Mage::getBaseUrl();?><?php echo $use['value'] ?>"><?php echo $this->htmlEscape( $use['value'] ) ?></a>

 

Important part from above:

<?php echo $use['value'] ?>

 

$use['value'] is used for the end of the url, for example www.website.com/candlemaking

 

The trouble is when $use['value'] has spaces or &

bike.png

Suggest a poll for Tip.it - Here!

In html links spaces are automatically replaced by %20...you can substitute dashes but then the link won't work.

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

  • Author

Which is what's happening, so instead I want to change spaces :arrow: "-" and "&" :arrow: "and" within the string.

 

Like if I have a page www.website.com/home-projects-and-hobbies/ but the string is "home projects & hobbies", how can I change it to use the dashes (as well as "&" to "and")?

bike.png

Suggest a poll for Tip.it - Here!

  • Author

Just as an fyi, this worked; thanks John.

 

<?php
$str = $use['value'];
$order = array(' ', '&');
$replace = array('-', 'and');

$newstr = str_replace($order, $replace, $str);

echo $newstr;
?>

bike.png

Suggest a poll for Tip.it - Here!

Just as an fyi, this worked; thanks John.

 

<?php
$str = $use['value'];
$order = array(' ', '&');
$replace = array('-', 'and');

$newstr = str_replace($order, $replace, $str);

echo $newstr;
?>

Np.

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.