Jump to content

[SOLVED] str_replace URL


l0rdz3r0

Recommended Posts

hello everyone i need some help in this i tried many ways i google it etc...

and yes i am new in this...

Here goes my headaches

 

$output1='<a href="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" rel="nofollow">

<img src="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" border="0" alt="name" /></a>';

 

 

i need to change /img/ to /thumb/ at <img src...

 

$links = str_replace('/img/', "/thumb/", $output1); this works but it changes the href too

what i need is some help to the function only change in <img src

somenting like this

$links = str_replace('/img/ |<img src', "/thumb/", $output1);

 

 

 

so the output will be

<a href="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" rel="nofollow">

<img src="http://www4.site.com/photo/a/user/thumb/pict/name1212.jpg" border="0" alt="name" /></a>

Link to comment
Share on other sites

excuse me if i'm over-simplifying this, but couldn't you just do this:

 

$output1='<a href="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" rel="nofollow">
<img src="http://www4.site.com/photo/a/user/thumb/pict/name1212.jpg" border="0" alt="name" /></a>';

 

why do you need to use str_replace() when you can just do it manually?  perhaps a little more insight to the use of this might help shed some better responses.

 

EDIT: if that won't do it for you, did you try this:

 

$output1 = str_replace ('<img src="http://www4.site.com/photo/a/user/img/', '<img src="http://www4.site.com/photo/a/user/thumb/', $output1);

 

pretty straight forward.

Link to comment
Share on other sites

mrMarcus, i'm assuming that those are example values for various parts of the URL.

i'm not sure that's the case.

 

all that is needed is when there is an <img> tag present, have the directory point to /thumb/ and the <a> tag point to /img/.

 

now, call me crazy, but i would just hard-code it in if it's to be a constant.

 

for example, assume a setup like this:

<?php
$sql = mysql_query ("SELECT * FROM `table`");

while ($res = mysql_fetch_assoc ($sql))
{
$output1 = '<a href="http://www4.site.com/photo/a/user/img/pict/'.$img.'" rel="nofollow"><img src="http://www4.site.com/photo/a/user/thumb/pict/'.$img.'" border="0" alt="name" /></a>';

echo $output1;
}
?>

 

why the need to replace at all?  code-in one dir for thumbs, one for full-size.

 

i could be mistaken with how i interpreted the initial problem, and you're absolutely right, regex would take care of an issue like this .. but, is there really an issue?

 

Link to comment
Share on other sites

 

$output1 = str_replace ('<img src="http://www4.site.com/photo/a/user/img/', '<img src="http://www4.site.com/photo/a/user/thumb/', $output1);

 

pretty straight forward.

 

No i cant do that becouse a i get a list with multiple urls

 

 

for ex.

<a href="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" rel="nofollow">

<img src="http://www4.site.com/photo/a/user/img/pict/name1212.jpg" border="0" alt="name" /></a>

<a href="http://www8.site.com/photo/a/user/img/pict/na433212.jpg" rel="nofollow">

<img src="http://www8.site.com/photo/a/user/img/pict/na433212.jpg" border="0" alt="name" /></a>

...

 

that why i need to get some that only change from img src...

 

Link to comment
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.