ebchost Posted June 11, 2011 Share Posted June 11, 2011 For example <img src="http://www.vesti-online.com/data/images/2011-06-05/156013_sampioni_kf.jpg?ver=1307647416"><br/>Upravo zavrÅ¡ena klupska sezona obeležena je potpunom dominacijom Partizana, s obzirom da su sekcije naÅ¡eg najbrojnijeg sportskog druÅ¡tva osvojile Äak 11 pehara u pet najpopularnijih kolektivnih sportova.<br/><br/> this is part of som news article wich i have in my database in tabele. How i can to separete imege url from rest part of text in 2 diferent variable $image_url = " url image value from item"; $text = "rest of text value"; in this example final resolt wil be $image_url = "http://www.vesti-online.com/data/images/2011-06-05/156013_sampioni_kf.jpg"; $text = "Upravo zavrÅ¡ena klupska sezona obeležena je potpunom dominacijom Partizana, s obzirom da su sekcije naÅ¡eg najbrojnijeg sportskog druÅ¡tva osvojile Äak 11 pehara u pet najpopularnijih kolektivnih sportova."; thanks. Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/ Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 You'll find that there are various ways to do this. To isolate the URL, I am going to use a function called preg_match() which uses a regular expression to match substrings to a pattern. $pattern = '/\"(.?)\"/'; preg_match($pattern, $subject, $matches) Where $subject will be the string with your img tag. To find the text after the URL, we will be doing the same thing, simply changing the search pattern a bit. $pattern = '/<br\/>(.?)<br\/>/i'; Simply use that pattern in the preg_replace() to find the string of text. $matches[0] will be the result that you want Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228382 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 Edit to my previous post. Replace the ? With * Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228387 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 $podaci = mysql_query("SELECT * FROM rss_vesti") or die(mysql_error()); while($row = mysql_fetch_assoc( $podaci )) { $naslov = $row['NASLOV']; $sadrzaj = $row['SADRZAJ']; $izvor = $row['IZVOR']; $datum = $row['DATUM']; ?> <table> <tr> <td> <?php preg_match_all('/<ul>(.*?)<\/ul>/i', $sadrzaj, $matches); echo $matches[0][0]; ?> </td> </tr> </table> <?php } i hava emty screen, no resolts? But, in your original code, resolt egsisting. Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228406 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 he, i look wrong place for code Sorry Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228408 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 he, i look wrong place for code Sorry everything work okay for you? Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228426 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 http://www.moravaprom.com/ebchost/prikaz.php you can see the problem hiar ? I believe that the problem is in quotes "url" ? Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228433 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 yes, make the variable the src of your images, do not wrap it in single quotes, if you dont want to do it that way, you can use str_replace() on the matches of the pre_match() code that i gave you earlier, like so $matches = str_replace($matches, '"', ''); Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228441 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 now pictures have value "http://www.moravaprom.com/ebchost/prikaz.php" Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228447 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 looks like there source is empty, do you have the variable set as the source Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228456 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 $podaci = mysql_query("SELECT * FROM rss_vesti") or die(mysql_error()); while($row = mysql_fetch_assoc( $podaci )) { $naslov = $row['NASLOV']; $sadrzaj = $row['SADRZAJ']; $izvor = $row['IZVOR']; $datum = $row['DATUM']; ?> <table> <tr> <td> <?php $garbage = 'just some bs <ul><li>text</li><li>text</li><li>text</li></ul>just some more bs'; $test = preg_match_all('/\"(.*?)\"/', $sadrzaj, $matches); echo $matches[0][0]; $slika = str_replace($matches, '"', ''); echo $slika; echo "<img src='$slika' alt='' height='100' width='100'/>"; ?> </td> </tr> </table> <?php } This code i use in this moment resolt can be check it in http://www.moravaprom.com/ebchost/prikaz.php adres Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228463 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 <?php $garbage = 'just some bs <ul><li>text</li><li>text</li><li>text</li></ul>just some more bs'; $test = preg_match_all('/\"(.*?)\"/', $sadrzaj, $matches); echo $matches[0][0]; $slika = str_replace($matches[0][0], '"', ''); //need to add distinct positioning echo $slika; echo "<img src='$slika' alt='' height='100' width='100'/>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228464 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 nothing new... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228466 Share on other sites More sharing options...
ebchost Posted June 11, 2011 Author Share Posted June 11, 2011 $slika = str_replace( '"','',$matches[0][0]); this is give resolt Syntax str_replace(find,replace,string,count) thenks a lot Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228475 Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 my mistake, had the parameters backwards. Glad you corrected my error Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1228478 Share on other sites More sharing options...
ebchost Posted June 19, 2011 Author Share Posted June 19, 2011 i think we (i) need update for this problem How to correct this (upgrade)? for some image, i have url value like this $image = "width: 180px; float: right; margin:3px; text-align:center;" you can check it hiar: http://moravaprom.com/ebchost/index.php (as you can see, i make progres in my work, but i still have litle off beginig problem) thanks in forvard Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1231812 Share on other sites More sharing options...
fugix Posted June 19, 2011 Share Posted June 19, 2011 Can you pinpoint your problem for us please Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1231817 Share on other sites More sharing options...
ebchost Posted June 19, 2011 Author Share Posted June 19, 2011 Can you pinpoint your problem for us please this is code for echo rss value $items = $rss_link->channel->item; foreach($items as $item) { $title = $item->title; echo "<h2>LOGO:</h2>$title</br>"; $link = $item->link; echo "<h2>LINK :</h2>$link</br>"; $published_on = $item->pubDate; echo "<h2>Published_on:</h2> $published_on</br>"; $description = $item->description; $descritpion_strip = strip_tags($description); $description_trim = trim($descritpion_strip); echo "<h2>description_trim:</h2> $description_trim</br><hr>"; $image_object = preg_match_all('/\"(.*?)\"/', $description, $matches); $image = str_replace( '"','',$matches[0][0]); } this part of code colecting url of image $image_object = preg_match_all('/\"(.*?)\"/', $description, $matches); $image = str_replace( '"','',$matches[0][0]); and sometimes, show bad value for example: $image = "width: 180px; float: right; margin:3px; text-align:center;" How can I avoid this and get the correct value image url? thanks Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1231827 Share on other sites More sharing options...
fugix Posted June 19, 2011 Share Posted June 19, 2011 Okay we are going to expand on the reg exp to eliminate the possibility of grabbing CSS. $image_object = preg_match_all('/src="(.*?)"/', $description, $matches); $image = str_replace( '"','',$matches[0][0]); Quote Link to comment https://forums.phpfreaks.com/topic/239076-separate-text-from-the-image-into-two-different-variables/#findComment-1231858 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.