igor berger Posted May 22, 2007 Share Posted May 22, 2007 Sorry guys to bother you with this simple thing, but my eyes are almost blind to look at php.net, from working on my Website too much, and I really need to get this done. I need to split this string in two parts <BR><BR><A href="http://www.somewebsite">Product</A> We can use the space as a spliting eliment. I know I have been PITA, but could really use your help! Thank you, Igor Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/ Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 Your explanation leaves much to be desired. Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258952 Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 agreed... where do you want it split? are the splits always going to be in the same place.........................? Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258953 Share on other sites More sharing options...
georg Posted May 22, 2007 Share Posted May 22, 2007 http://php.net/explode Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258956 Share on other sites More sharing options...
igor berger Posted May 22, 2007 Author Share Posted May 22, 2007 Yes always the same place! Just need to seperate two part, using the first blank space as the seperater. Sorry forgot to put it in the code tags. So split between the A h in two parts. <BR><BR><A href="http://www.somewebsite">Product</A> Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258968 Share on other sites More sharing options...
georg Posted May 22, 2007 Share Posted May 22, 2007 try this: $str = '<BR><BR><A href="http://www.somewebsite">Product</A>'; $part1 = substr($str, 0, 10); $part2 = substr($str, 11); Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258983 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 You can also use the explode() function: <?php $str = '<BR><BR><A href="http://www.somewebsite">Product</A>'; list($part1,$part) = explode(' ',$str,2); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-258996 Share on other sites More sharing options...
igor berger Posted May 22, 2007 Author Share Posted May 22, 2007 Thank you. explode should be good, unless they stick another space someplace before A h. I think I rather explode by A and then stick the A back into the string, this will eliminate a possibility of error. Thank you Ken Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259366 Share on other sites More sharing options...
per1os Posted May 22, 2007 Share Posted May 22, 2007 Just a spin off of ken's function sorta <?php $str = '<BR><BR><A href="http://www.somewebsite">Product</A>'; list($part1,$part) = spliti('<A href',$str); $part = '<A href' . $part; ?> www.php.net/spliti is a case in-sensitive split function much like explode except, well its case in-sensitive. I just love how there are about 10 different ways to do 1 thing in the programming world =) Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259372 Share on other sites More sharing options...
effigy Posted May 22, 2007 Share Posted May 22, 2007 What are you doing with this data, exactly? That's an awkward place to split. Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259375 Share on other sites More sharing options...
corbin Posted May 22, 2007 Share Posted May 22, 2007 This is kinda a weird suggestion, and just ignore it if this surpasses your skill level.... If you're trying to pull the url from the link, I suggest exploding " so that $explode_var[1] would be the url and you wouldn't have to mess with stripping quotes or formatting your output to match a certain way.... Also, if you wanted to get really fancy with it, you could use regular expressions (this is the part that you can freely ignore ;p). <?php $url = "<a href=\"http://google.com/\">Google</a>"; //$pattern = "/<a href=(\"|')(http|https):\/\/([a-zA-Z])(?:\"|')>/"; $pattern = "/<a href=\"(.*)\">/"; $pattern = "/<a ([.*]?)href=(?:\"|')(.*)(?:\"|')([.*]?)>(.*)<\/a>/"; // 1 2 3 4 5 6 //1 checks for any character between '<a href' (a class= tag or something like that maybe...) the ? makes this optional //2 matches either " or ' after href=..... The ?: makes it not store it in the array of parenthesis //3 matches any character between href=("|') and ("|') (this would be your url.) //4 see 2 //5 this matches any content (it's optional) between '" and '>' //examples could be <a href=""*start matching* *stop matching*> or <a href=""*start matching*/*stop matching*> //6 matches any thing inbetween > and </a> (the link text) if(preg_match($pattern, $url, $matches)) { //print_r($matches); //use this to dump matches echo 'The url is <i>' . $matches[2] . '</i>, and the text for the url is <i>' . $matches[4] . '</i>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259391 Share on other sites More sharing options...
igor berger Posted May 22, 2007 Author Share Posted May 22, 2007 Oh I just need to stick rel="nofollow" in the anchor link! This is for my affiliate product links not to leak PR. I got the links from xml files, which I extracted to a database and now serving based on product correlation. When I extracted the data I was not thinking of doing any manipulation to the anchor link, so extracted it as HTML not uri. But I do not even know if this will help with Google, it got to be very smart now days. I think it ignores these links anyway because it finds many of them on my Website. Also Google got to be so smart in duplicate content, that even if you have content from x number affiliates concocted on one page, it parses blocks of data and compares them to global recourses for duplicity. If duplicate, it puts the pages in supplementary index. Now days, there is little original content on the internet, because how many different ways can you call a horse a horse! <__> So what SERP's are looking for is originality in content, like this forum! If you guys needs to get some solid ideas about SEO, come to http://groups.google.com/group/Google_Webmaster_Help Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259459 Share on other sites More sharing options...
igor berger Posted May 23, 2007 Author Share Posted May 23, 2007 Okay guys, thank you for all your help. I am sure there are many ways to do this, but to me simple is best, and as long as it is not error prone I am content. <?php $rel='rel="nofollow"'; $str = '<BR><BR><A href="http://www.somewebsite">Product</A>'; list($part1,$part2) = explode('href',$str,2); $anchor=$part1.$rel.' href'.$part2; echo $anchor; ?> This is an implementation for it. http://www.travelconnecxion.com/hotels/hotel.php?hotel_id=57881 I can use a url rewrite, I will get to doing it when I will get a chance, but I do not think a product description url will put the page back into Google’s main index permenatly. These type of pages go in and out and back in to Google’s main index. I think to permemnatly keep them in the index, I should create a comment section for each page, and populate it with authoritative commentary about the product. Something like www.tripadvisor.com does! Now to create the plugin in PHP should be relatively easy, but to add relative commentary to 25,000 pages would be Mission Impossible! But I guess this is what community building is about! Oh and my eyes are getting better after a little rest! Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259488 Share on other sites More sharing options...
effigy Posted May 23, 2007 Share Posted May 23, 2007 TMTOWTDI: <pre> <?php $str = '<BR><BR><A href="http://www.somewebsite">Product</A>'; echo $str = preg_replace('/(?<=<A )/', 'rel="nofollow" ', $str); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259835 Share on other sites More sharing options...
igor berger Posted May 23, 2007 Author Share Posted May 23, 2007 effigy, I am not really good with regex. I presume it is regex? Can you explain the logic behind this? '/(?<=<A )/' Thank you Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259863 Share on other sites More sharing options...
effigy Posted May 23, 2007 Share Posted May 23, 2007 (?<= ... ) is a positive lookbehind. It doesn't match a character, but a position. In this case it's matching the infinitesimal position between the space and the "h" in "href," which is where it inserts the replacement. Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259867 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 I know what a positive or negative lookbehind is, but maybe you can explain me what this acronym stands for: TMTOWTDI: Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259881 Share on other sites More sharing options...
igor berger Posted May 23, 2007 Author Share Posted May 23, 2007 Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259918 Share on other sites More sharing options...
effigy Posted May 23, 2007 Share Posted May 23, 2007 I know what a positive or negative lookbehind is, but maybe you can explain me what this acronym stands for: TMTOWTDI: An expression used when presenting new methods. http://en.wikipedia.org/wiki/TMTOWTDI Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-259972 Share on other sites More sharing options...
448191 Posted May 24, 2007 Share Posted May 24, 2007 Ah, I see. I like this part of the Zen of Python: # There should be one—and preferably only one—obvious way to do it. # Although that way may not be obvious at first unless you're Dutch. Quote Link to comment https://forums.phpfreaks.com/topic/52480-can-you-help-me-split-a-string-in-two-parts/#findComment-260605 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.