Jump to content

Recommended Posts

Hello experts, I am having trouble with the following bit of php code. I am trying to extract phrases from a big string and replace them with themselves as a link. I have included the whole code at the end of this post. Basically I take the long string which is placed in the variable $value, use the str_replace function to get rid of all the HTML which places the phrases i need in the array $links. I know this is working because when I echo the 1st phrase ($link[0]) it returns the phrase. The problem arises when I use str_replace to find the phrase and replace it with the link. This does not work when I use the variable $link[$id] as the 1st parameter in the str_replace function but it works if i use, for example, the letter 'a' as the 1st parameter.

 

 

THIS WORKS----

 

$data=str_replace('a',"<a href=\"index.htm?page=designownlinks&message=".$links[$id]."\">".$links[$id]."</a>",$value);

 

THIS DOES NOT WORK----

 

$data=str_replace($links[$id],"<a href=\"index.htm?page=designownlinks&message=".$links[$id]."\">".$links[$id]."</a>",$value);

 

Can anybody help me figure this out? I thank you in advance for any help. The complete code follows:

 

 

<?php

 

$value="<p>Design your own blanket by choosing your favorite Polartec 200 blanket color and add your

personalized saying up to 15 words or choose one of our phrases or sayings. This is a great

way to commemorate a special occasion.</p>

<p><img src=\"../images/products/buildown2.gif\" alt=\"/\" /></p>

<h3>Birthdays</h3>

<ul>

<li>\"Age is a number, and mine is unlisted.\"</li>

<li>\"If things get better with age then I'm approaching magnificent\"</li>

<li>\"Older than dirt\"</li>

<li>\"If I rest will I rust?\"</li>

<li>\"30 and Fabulous\"</li>

 

<li>\"40 and Fabulous\"</li>

<li>\"50 and Fabulous\"</li>

<li>\"60 and Fabulous\"</li>

<li>\"Not getting older just Better\"</li>

</ul>

<div>

<h3>Mother/Father</h3>

<ul>

<li>\"Some people bond My Mom and me are Crazy-Glued\"</li>

<li>\"Worlds best Mom\"</li>

 

<li>\"Worlds best Dad\"</li>

<li>\"God couldn't be everywhere so he created Mothers\"</li>

<li>\"My greatest gift was heaven sent ,I call him Dad\"</li>

<li>\"The only man a * can trust is her Daddy\"</li>

<li>\"King of the Remote\"</li>

<li>\"Home is where your story begins\"</li>

<li>\"A Father is someone you look up to no matter how tall you are\"</li>

</ul>

</div>

<div>

 

<h3>Grandparents</h3>

<ul>

<li>\"Our hearts belong to Grandma\"</li>

<li>\"Mirror Mirror on the wall I am my mother after all\"</li>

<li>\"The best thing at Grandpa's house is Grandma\"</li>

<li>\"Grammy Award Winner (best performance in a continuing role)\"</li>

<li>\"When a child is born so is a Grandmother\"</li>

<li>\"Grandmas are Antique little *\"</li>

</ul>

</div>

 

<div>

<h3>Daughter/Son</h3>

<ul>

<li>\"How blessed I am, how fortunate I've been...that you are my Daughter and also my friend\"</li>

<li>\"The princess sleeps here\"</li>

<li>\"A Daughter is just a little * who grows up to be a Friend\"</li>

<li>\"Daughters are forever- I'm so glad your mine\"</li>

<li>\"Call your Mother...she worries\"</li>

<li>\"Love made you a Daughter - in - law...but your heart makes you a Special Daughter\"</li>

<li>\"All the dreams I prayed you'd be are all the things you are. You were once my little * - and now my shining star\"</li>

 

<li>\"You have always been so special in all the things you've done I'm so proud of you , simply because you are my son\"</li>

<li>\"Mothers of little boys work from son up to son down\"</li>

</ul>

</div>

<div>

<h3>Sister</h3>

<ul>

<li>\"My sister is my best friend, forever and ever\"</li>

<li>\"Sisters are tied together with Heartstrings\"</li>

<li>\"To have a Sister is to have a Lifelong friend!\"</li>

<li>\"A Sister is a friend who listens with her heart\"</li>

 

<li>\"There is no friend like a Sister and no Sister quite like you\"</li>

</ul>

</div>

<div>

<h3>*/Children</h3>

<ul>

<li>\"The princess sleeps here\"</li>

<li>\"The prince sleeps here\"</li>

<li>\"Good night, don't let the bed bugs bite\"</li>

<li>\"Princess\"</li>

<li>\"God's Little Blessing\"</li>

 

<li>\"God Bless this little one\"</li>

<li>\"Now I lay me down to sleep\"</li>

</ul>

</div>

<div>

<h3>Friendship</h3>

<ul>

<li>\"It takes a long time to grow old friends\"</li>

<li>\"We'll be friends 'till we're blue in the hair\"</li>

<li>\"Friends are angels who lift us up when we believe our wings have forgotten how to fly\"</li>

<li>\"Old friends are the best friends\"</li>

 

<li>\"A friend is someone who knows the song in your heart and can sing it back you when you've forgotten the words\"</li>

<li>\"Good friends are like angels you don't have to see them to know they are there\"</li>

<li>\"The Most Valuable Antiques are Old Friends\"</li>

<li>\"You will always be my best friend... You know too much\"</li>

<li>\"A best friend is a sister that destiny forgot to give you\"</li>

<li>\"You will always be my Best Friend\"</li>

<li>\"Friends listen to what you say, Best Friends listen to what you don't say \"</li>

<li>\"Friendship is not a big thing...it's a million little things\"</li>

<li>\"I have a bouquet of friends but you are my rose\"</li>

 

<li>\"Side by side or miles apart dear friends are always close\"</li>

<li>\"When I count my blessings I count you twice\"</li>

<li>\"When God made you he was just showing off\"</li>

</ul>

</div>

<div>

<h3>Dogs</h3>

<ul>

<li>\"A dog wags his tail with his heart\"</li>

<li>\"Dogs leave paw prints on you heart\"</li>

<li>\"Dogs are children in fur coats\"</li>

 

<li>\"Never underestimate the Warmth of a Cold Nose\"</li>

</ul>

</div>

<div>

<h3>Marriage</h3>

<ul>

<li>\"Happiness is being married to your best friend\"</li>

<li>\"Have I told you lately that I love you?\"</li>

</ul>

</div>

<div>

<h3>Sports</h3>

 

<ul>

<li>\"If I can't fish in heaven I'm not going\"</li>

<li>\"If I can't golf in heaven I'm not going\"</li>

<li>\"If I can't hunt in heaven I'm not going\"</li>

<li>\"Cast and you shall receive\"</li>

<li>\"A man's place is on his boat\"</li>

</ul>

</div>

<div>

<h3>I'd rather be...</h3>

<ul>

 

<li>\"I'd rather be fishing.\"</li>

<li>\"I'd rather be boating\"</li>

<li>\"I'd rather be on Cape Cod\"</li>

<li>\"I'd rather be in Paris\"</li>

<li>\"I'd rather be in the Hamptons\"</li>

<li>\"I'd rather be playing golf\"</li>

</ul>

</div>

<div>

<h3>Miscellaneous</h3>

 

<ul>

<li>\"I Love Slots\"</li>

<li>\"I Love Bingo\"</li>

<li>\"If you're lucky enough to have a house by the water You're lucky enough\"</li>

<li>\"We don't stop laughing because we grow old. We grow old because we stop laughing\"</li>

<li>\"Queen of everything\"</li>

<li>\"King of everything\"</li>

<li>\"Once Upon A Time ...\"</li>

<li>\"Heaven is a little closer in a cottage by the sea\"</li>

 

<li>\"Heaven is a little closer in a cabin in the mountains\"</li>

<li>\"Heaven is a little closer in a cottage by the lake\"</li>

<li>\"The Goddess is feeling lazy today\"</li>

<li>\"* & Kisses\"</li>

<li>\"Insecurity blanket\"</li>

<li>\"Security blanket\"</li>

<li>\"My blankie\"</li>

<li>\"Families are like fudge, mostly sweet with a few nuts\"</li>

 

</ul>

</div>

<div>

<h3>Silly Sayings</h3>

<ul>

<li>\"Whatever you are be a good one\"</li>

<li>\"A woman and Her Shoes.. It's a beautiful thing\"</li>

<li>\"Chocolate Makes My Clothes shrink\"</li>

<li>\"The only thing more overrated than natural childbirth is the joy of owning your own business\"</li>

<li>\"A man's home is his castle - until the Queen arrives\"</li>

<li>\"Behind every successful woman is herself\"</li>

 

<li>\"If the shoe fits, buy it in every color\"</li>

</ul>

</div>

<div>

<h3>Life</h3>

<ul>

<li>\"Life is like a cup of tea, it's all in how you make it\"</li>

<li>\"Live Well, Love Much, Laugh Often\"</li>

<li>\"When life gives you lemons, make lemonade\"</li>

<li>\"You are my Sunshine\"</li>

<li>\"Dance as if no one is watching\"</li>

 

<li>\"I believe in angels\"</li>

<li>\"Dream\"</li>

<li>\"Plant your Dreams and Miracles Will Grow\"</li>

<li>\"Leave room in your garden for Angels to Dance\"</li>

</ul>

</div>

<div>

<h3>Military</h3>

<ul>

<li>\"Welcome Home Johnny\"</li>

<li>\"Proud Parents of a United States Soldier\"</li>

 

<li>\"Proud Parents of a United States Marine\"</li>

<li>\"Proud Parents of a United States Sailor\"</li>

<li>\"Ooh - rah !\"</li>

</ul>

</div>

<div>

<h3>Foreign Sayings</h3>

<ul>

<li>\"Sempre Famiglia (Family Forever)\"</li>

<li>\"Cent Anni ( May We live To Be A Hundred Years )\"</li>

<li>\"Mi Casa es Su Casa ( My Home is Your Home)\"</li>

 

<li>\"La Vita E Bella ( It's a beautiful life)\"</li>

<li>\"Je T'aime ( I Love You)\"</li>

</ul>

</div>

<p> </p>";

 

 

 

$old = array("<li>", '"',"</div><div>", '</h3>','<h3>Mother/Father','<h3>Grandparents','<h3>Daughter/Son',

'<h3>Sister','<h3>*/Children','<h3>Friendship','<h3>Dogs','<h3>Marriage','<h3>Sports',

'<h3>I\'d rather be...','<h3>Miscellaneous','<h3>Silly Sayings','<h3>Life','<h3>Military',

'<h3>Foreign Sayings','<p>Design your own blanket by choosing your favorite Polartec 200 blanket color and add your

personalized saying up to 15 words or choose one of our phrases or sayings. This is a great

way to commemorate a special occasion.</p>

<p><img src=../images/products/buildown2.gif alt=/ /></p>

<h3>Birthdays

','<div>

','</div>', '.','</li>','<ul>','</ul>');

 

$new = array("", "","", "","","","","","","","","","","","","","","","","","","","","<br />","","");

 

$new_text = str_replace($old, $new, $value);

 

$links=explode('<br />',$new_text);

 

$id=0;

 

echo $links[$id];

 

$data=str_replace('a',"<a href=\"index.htm?page=designownlinks&message=".$links[$id]."\">".$links[$id]."</a>",$value);

 

echo $data;

?>

Link to comment
https://forums.phpfreaks.com/topic/151091-solved-variable-issue-with-str_replace/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.