2

how can i make this code display $anchor with spaces. I would have Text Anchor1 and Text Anchor two insitead of TextAnchor1 and TextAnchor2. Thank you

$currentsite = get_bloginfo('wpurl');
           $sites = array(
           'TextAnchor1' => 'http://www.mysite1.com',
           'TextAnchor2' => 'http://www.mysite2.com'
           );
           foreach($sites as $anchor => $site) 
           {
           if ( $site !== $currentsite ){echo '<li><a href="'.$site.'" title="'.$anchor.'" target="_blank">'.$anchor.'</a></li>';}
           } 

4 Answers 4

2

So, as you $anchor values probably aren't hard-coded, I assume what you really need is a function that takes a string as an argument and inserts spaces before any capital letters or numbers.

function splitWords($s){
return trim(preg_replace('/([A-Z0-9])/', ' \1', $s));
}

Later, when writing output, instead of $anchor, you can use splitWords($anchor).

Sign up to request clarification or add additional context in comments.

Comments

1
$sites = array(
           'Text Anchor 1' => 'http://www.mysite1.com',
           'Text Anchor 2' => 'http://www.mysite2.com'
           );

Comments

1

Ooh, ooh, my turn.

$sites = array(
           'Text Anchor 1' => 'http://www.mysite1.com',
           'Text Anchor 2' => 'http://www.mysite2.com'
           );

2 Comments

I was totally first. I blame anti virus software
Looks like the other guy pulled the old "respond with anything then edit" switcharoo anyway.
0

Just change to:

$sites = array(
    'Text Anchor' => 'http://www.mysite1.com',
    'My Text Anchor' => 'http://www.mysite2.com'
);

1 Comment

Do i have to have the same number of words? I mean, can i have 'text anchor' and 'my text anchor'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.