Prev: a quick question about array keys
Next: Looking for open source Learning Management System suggestions
From: Karl DeSaulniers on 31 Aug 2010 15:31 Hi, Say I have some text. $text = 'You can logon here: <a href="http://website.com/shop/ index.php?username='.$username.'">http://website.com/shop/index.php? username='.$username.'</a>. This link will take you to your web browser to login.'.$eol; I want to be able to strip the "<a href="http://website.com/shop/ index.php?username='.$username.'">" and </a>. Leaving just the http://website.com/shop/index.php?username='. $username.' text, so it would end up like. $text = 'You can logon here: http://website.com/shop/index.php? username='.$username.'. This link will take you to your web browser to login.'.$eol; I have tried MANY different ways and have no success. Can anyone help me? TIA Karl DeSaulniers Design Drumm http://designdrumm.com
From: Ashley Sheridan on 31 Aug 2010 15:32 On Tue, 2010-08-31 at 14:31 -0500, Karl DeSaulniers wrote: > Hi, > Say I have some text. > > $text = 'You can logon here: <a href="http://website.com/shop/ > index.php?username='.$username.'">http://website.com/shop/index.php? > username='.$username.'</a>. This link will take you to your web > browser to login.'.$eol; > > I want to be able to strip the "<a href="http://website.com/shop/ > index.php?username='.$username.'">" and </a>. > Leaving just the http://website.com/shop/index.php?username='. > $username.' text, so it would end up like. > > > $text = 'You can logon here: http://website.com/shop/index.php? > username='.$username.'. This link will take you to your web browser > to login.'.$eol; > > I have tried MANY different ways and have no success. > Can anyone help me? > TIA > > > Karl DeSaulniers > Design Drumm > http://designdrumm.com > strip_tags() will do the job here. Thanks, Ash http://www.ashleysheridan.co.uk
From: Karl DeSaulniers on 31 Aug 2010 16:01 On Aug 31, 2010, at 2:32 PM, Ashley Sheridan wrote: > On Tue, 2010-08-31 at 14:31 -0500, Karl DeSaulniers wrote: >> >> Hi, >> Say I have some text. >> >> $text = 'You can logon here: <a href="http://website.com/shop/ >> index.php?username='.$username.'">http://website.com/shop/index.php? >> username='.$username.'</a>. This link will take you to your web >> browser to login.'.$eol; >> >> I want to be able to strip the "<a href="http://website.com/shop/ >> index.php?username='.$username.'">" and </a>. >> Leaving just the http://website.com/shop/index.php?username='. >> $username.' text, so it would end up like. >> >> >> $text = 'You can logon here: http://website.com/shop/index.php? >> username='.$username.'. This link will take you to your web browser >> to login.'.$eol; >> >> I have tried MANY different ways and have no success. >> Can anyone help me? >> TIA >> >> >> Karl DeSaulniers >> Design Drumm >> http://designdrumm.com >> > > strip_tags() will do the job here. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > Hi Ash, I tried that, but it did not work. I do not want it to strip all tags, just the <a href=""></a>. so if there was a <p> or <br />. I don't want those removed. There is more text than just what I posted. This is what I am trying currently. This is someones code from a forum that I am trying to adopt. //CODE start function strip_only($str, $tags) { // Thanks Steve if(!is_array($tags)) { $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags)); if(end($tags) == '') array_pop($tags); } foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>] *>#is', '', $str); return $str; } $str = '<p style="text-align:center">Paragraph</p><strong>Bold</ strong><br/><span style="color:red">Red</span><h1>Header</h1>'; echo strip_only($str, array('p', 'h1')); echo strip_only($str, '<p><h1>'); //CODE end I was using it like so. $text = strip_only($text, array('a')); or $text = strip_only($text, '<a>'); But got my results back like: 'You can logon here: href="http://website.com/shop/ index.php?username='.$username.'">http://website.com/shop/index.php? username='.$username.'. This link will take you to your web browser to login.'.$eol; uugh.. Karl DeSaulniers Design Drumm http://designdrumm.com
From: Karl DeSaulniers on 31 Aug 2010 16:07 On Aug 31, 2010, at 2:34 PM, Joshua Kehn wrote: > On Aug 31, 2010, at 3:31 PM, Karl DeSaulniers wrote: > >> Hi, >> Say I have some text. >> >> $text = 'You can logon here: <a href="http://website.com/shop/ >> index.php?username='.$username.'">http://website.com/shop/ >> index.php?username='.$username.'</a>. This link will take you to >> your web browser to login.'.$eol; >> >> I want to be able to strip the "<a href="http://website.com/shop/ >> index.php?username='.$username.'">" and </a>. >> Leaving just the http://website.com/shop/index.php?username='. >> $username.' text, so it would end up like. >> >> >> $text = 'You can logon here: http://website.com/shop/index.php? >> username='.$username.'. This link will take you to your web >> browser to login.'.$eol; >> >> I have tried MANY different ways and have no success. >> Can anyone help me? >> TIA >> >> >> Karl DeSaulniers >> Design Drumm >> http://designdrumm.com >> > > Would it be safe to simply strip out anything between < and > ? > > Regards, > > -Josh > ____________________________________ > Joshua Kehn | Josh.Kehn(a)gmail.com > http://joshuakehn.com > Hi Josh, Safe? Not sure what you mean. The text is for an email that is originally done in html code, that when sent, checks to see if the recipiant can get html emails. if not the text version is sent, but I want to remove any <a href""></ a> tags before sending. This is how it starts: $text = 'You can logon here: <a href="http://website.com/shop/ index.php?username='.$username.'">http://website.com/shop/index.php? username='.$username.'</a>. This link will take you to your web browser to login.'.$eol; This is how I want it if they dont get the thml version $text = 'You can logon here: http://website.com/shop/index.php? username='.$username.'. This link will take you to your web browser to login.'.$eol; Hope that clarifies Best, Karl DeSaulniers Design Drumm http://designdrumm.com
From: Ashley Sheridan on 31 Aug 2010 16:06 On Tue, 2010-08-31 at 15:01 -0500, Karl DeSaulniers wrote: > On Aug 31, 2010, at 2:32 PM, Ashley Sheridan wrote: > > > On Tue, 2010-08-31 at 14:31 -0500, Karl DeSaulniers wrote: > >> > >> Hi, > >> Say I have some text. > >> > >> $text = 'You can logon here: <a href="http://website.com/shop/ > >> index.php?username='.$username.'">http://website.com/shop/index.php? > >> username='.$username.'</a>. This link will take you to your web > >> browser to login.'.$eol; > >> > >> I want to be able to strip the "<a href="http://website.com/shop/ > >> index.php?username='.$username.'">" and </a>. > >> Leaving just the http://website.com/shop/index.php?username='. > >> $username.' text, so it would end up like. > >> > >> > >> $text = 'You can logon here: http://website.com/shop/index.php? > >> username='.$username.'. This link will take you to your web browser > >> to login.'.$eol; > >> > >> I have tried MANY different ways and have no success. > >> Can anyone help me? > >> TIA > >> > >> > >> Karl DeSaulniers > >> Design Drumm > >> http://designdrumm.com > >> > > > > strip_tags() will do the job here. > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > Hi Ash, > I tried that, but it did not work. > I do not want it to strip all tags, just the <a href=""></a>. so if > there was a <p> or <br />. I don't want those removed. > There is more text than just what I posted. > > This is what I am trying currently. > This is someones code from a forum that I am trying to adopt. > > //CODE start > function strip_only($str, $tags) { // Thanks Steve > if(!is_array($tags)) { > $tags = (strpos($str, '>') !== false ? explode('>', > str_replace('<', '', $tags)) : array($tags)); > if(end($tags) == '') array_pop($tags); > } > foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>] > *>#is', '', $str); > return $str; > } > > $str = '<p style="text-align:center">Paragraph</p><strong>Bold</ > strong><br/><span style="color:red">Red</span><h1>Header</h1>'; > > echo strip_only($str, array('p', 'h1')); > echo strip_only($str, '<p><h1>'); > > //CODE end > > I was using it like so. > > $text = strip_only($text, array('a')); > or > $text = strip_only($text, '<a>'); > > But got my results back like: > 'You can logon here: href="http://website.com/shop/ > index.php?username='.$username.'">http://website.com/shop/index.php? > username='.$username.'. This link will take you to your web > browser to login.'.$eol; > uugh.. > > Karl DeSaulniers > Design Drumm > http://designdrumm.com > Look at the second argument to strip_tags() which allows you to specify a list of allowable tags. It will do what you want, you just need to look at the manual. Thanks, Ash http://www.ashleysheridan.co.uk
|
Next
|
Last
Pages: 1 2 3 Prev: a quick question about array keys Next: Looking for open source Learning Management System suggestions |